Cette page vous indique comment lancer depuis votre application une autre application de l'iPhone ou de l'iPod touch.
Attention, certaines fonctionnalités propres à l'iPhone (téléphone, sms) ne fonctionneront pas sur iPod touch.
App Store
Similaire à iTunes ou par exemple :
NSString *stringURL = @"http://clkuk.tradedoubler.com/click?p=23753&a=1665583&g=0&url=http://itunes.apple.com/fr/genre/mobile&partnerId=2003-software-applications/id36?mt=8";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Facebook
Vous pouvez lancer l'application Facebook sur une page spécifique :
NSString *stringURL = @"fb://profile";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Voici les différentes pages :
iTunes Store
Pour ouvrir l'application iTunes, utilisez n'importe quel lien vers des contenus du store :
NSString *stringURL = @"http://clkuk.tradedoubler.com/click?p=23753&a=1665583&g=0&url=http://itunes.apple.com/WebObjects/MZStore&partnerId=2003.woa/wa/viewPodcast?id=315986667";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
LinkedIn
Pour lancer LinkedIn sur l'appareil :
NSString *stringURL = @"linkedin://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Mail
Les URL suivantes lancement Mail et composent un message:
NSString *stringURL = @"mailto:test@example.com";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Vous pouvez ici donner plus d'informations sur le message :
NSString *subject = @"Message subject";
NSString *body = @"Message body";
NSString *address = @"test1@akosma.com";
NSString *cc = @"test2@akosma.com";
NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
Pour des contenus plus complexes, utilisez la fonction CFURLCreateStringByAddingPercentEscapes().
Messages
Pour ouvrir l'application Messages, utilisez le protocole suivant dans votre URL:
NSString *stringURL = @"sms:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Vous pouvez donner un destinataire mais pas le corps du message:
NSString *stringURL = @"sms:+12345678901";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Le numéro de téléphone doit respecter les conditions énoncées dans Téléphone plus bas dans cette page.
Plans
Les URL commençant par http://maps.google.com ouvrent "Plans" automatiquement:
NSString *title = @"title";
float latitude = 35.4634;
float longitude = 9.43425;
int zoom = 13;
NSString *stringURL = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@@%1.6f,%1.6f&z=%d", title, latitude, longitude, zoom];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Il semble que maps:// ouvre aussi la même application.
Safari
N'importe quelle URL avec http:// qui ne pointe pas vers maps.google.com ou www.youtube.com est envoyée à Safari :
NSString *stringURL = @"http://www.benoit-deldicque.com";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Skype
Utilisez le code suivant pour interagir (chat, call, add) avec un contact Skype :
NSString *stringURL = @"skype:bixcorp?call";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Téléphone
Les liens de téléphone commencent par "tel:" mais ne doivent pas contenir d'espaces ou de parenthèses:
NSMutableString *phone = [[@"+ 12 34 567 89 01" mutableCopy] autorelease];
[phone replaceOccurrencesOfString:@" " withString:@"" ptions:NSLiteralSearch range:NSMakeRange(0, [phone length])];
[phone replaceOccurrencesOfString:@"(" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [phone length])];
[phone replaceOccurrencesOfString:@")" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [phone length])];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phone]];
[[UIApplication sharedApplication] openURL:url];
YouTube
Les URL commençant par http://www.youtube.com ouvrent automatiquement l'application "YouTube" :
NSString *stringURL = @"http://www.youtube.com/watch?v=WofOn4mdC0s";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Fonctionne aussi avec les URL du lecteur Flash :
NSString *stringURL = @"http://www.youtube.com/v/WofOn4mdC0s";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];