Question

Comment puis-je faire un appel à partir d'une application ou lancer une application immédiatement après la fin d'appel? Je sais que cela est possible parce que certaines applications dans l'App Store font déjà.

Était-ce utile?

La solution

Je suis arrivé ce code à partir du site d'Apple et il fonctionne parfaitement:

-(IBAction) dialNumber:(id)sender{

NSString *aPhoneNo = [@"tel://" stringByAppendingString:[itsPhoneNoArray objectAtIndex:[sender tag]]] ; NSURL *url= [NSURL URLWithString:aPhoneNo];
 NSURL  *url= [NSURL URLWithString:aPhoneNo];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];

if ([osVersion floatValue] >= 3.1) { 
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 
[webview loadRequest:[NSURLRequest requestWithURL:url]]; 
webview.hidden = YES; 
// Assume we are in a view controller and have access to self.view 
[self.view addSubview:webview]; 
[webview release]; 
} else { 
// On 3.0 and below, dial as usual 
[[UIApplication sharedApplication] openURL: url];
}


}

Autres conseils

Je pense qu'il ya deux parties à cette

  1. L'application est déjà en cours d'exécution, et l'utilisateur reçoit un message indiquant un appel téléphonique est entrée, et a demandé d'accepter ou de rejeter
  2. L'utilisateur reçoit un appel téléphonique, mais l'application ne fonctionne pas

Dans le premier cas, votre UIApplication référence de classe pour plus de détails.

Dans le second cas, je ne sais pas, il se trouve avec le SDK officiel pour lancer votre application lorsqu'un appel téléphonique se termine. Pourriez-vous fournir une liste des applications qui font?

EDIT:

Je pense que je comprends ce que vous voulez dire maintenant. Vous devez suivre les conseils de @jessecurry, le openURL sur UIApplication avec un protocole de tel: fera un appel téléphonique. Quant à leur demande de « faire l'impossible » et ne pas quitter l'application lorsque l'appel téléphonique est fait, je ne sais pas comment ils l'ont fait parce que je ne l'écris. Ils pourraient utiliser un service externe VOIP comme Skype, ou simplement l'URL du chargement de l'intérieur d'un tel: invisible feuille Web. Ni dont je peux commenter parce que je ne l'ai pas essayé.

Il est fait à l'aide telprompt au lieu de tél. s'il vous plaît consulter le code suivant

[[UIApplication sharedApplication]      openURL: [NSURL URLWithString: @ "telprompt: 18004912200"]];

si vous souhaitez faire un appel à partir de votre application, vous pouvez utiliser une URL tel:.

Voici une méthode qui prend un numéro de téléphone en tant que chaîne et lance un appel.

- (void)dialNumber: (NSString*)telNumber
{
    // fix telNumber NSString
    NSArray* telComponents = [telNumber componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    telNumber = [telComponents componentsJoinedByString: @""];

    NSString* urlString = [NSString stringWithFormat: @"tel:%@", telNumber];
    NSURL* telURL = [NSURL URLWithString: urlString];
    //NSLog( @"Attempting to dial %@ with urlString: %@ and URL: %@", telNumber, urlString, telURL );

    if ( [[UIApplication sharedApplication] canOpenURL: telURL] )
    {
        [[UIApplication sharedApplication] openURL: telURL];
    }
    else
    {
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle: NSLocalizedString( @"Dialer Error", @"" ) 
                                                        message: [NSString stringWithFormat: NSLocalizedString( @"There was a problem dialing %@.", @"" ), telNumber] 
                                                       delegate: nil 
                                              cancelButtonTitle: NSLocalizedString( @"OK", @"" ) 
                                              otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top