Cela dépend de l'endroit où vous voulez mettre ce lien. S'il s'agit d'un UITextView, il vous suffit de l'activer.
textView.text = @"Some text with link in it : http://http://stackoverflow.com";
textView.dataDetectorTypes = UIDataDetectorTypeLink;
Plus d'informations sur iOS reference library.
Ou, si vous voulez ouvrir Safari programme:
NSURL *url = [ [ NSURL alloc ] initWithString: @"http://stackoverflow.com" ];
[[UIApplication sharedApplication] openURL:url];
[url release];
Si vous souhaitez partager sur Facebook, vous devez dire Safari pour ouvrir une URL qui affichera une page Facebook qui permet à l'utilisateur de partager . Voici un exemple:
NSString *urlString = @"http://stackoverflow.com";
//The url you want to share
NSString *title = "The Title of the Page";
//The title you want to be displayed on Facebook
NSString *shareUrlString = [NSString stringWithFormat:@"http://www.facebook.com/sharer.php?u=%@&t=%@", urlString , title];
//Create the URL string which will tell Facebook you want to share that specific page
NSURL *url = [ [ NSURL alloc ] initWithString:shareUrlString ];
//Create the URL object
[[UIApplication sharedApplication] openURL:url];
//Launch Safari with the URL you created
[url release];
//Release the object if you don't need it
En fait, je veux passer le lien de mon application sur facebook en utilisant Facebook API. Alors, comment dois-je formater mon texte de sorte qu'il fonctionne comme un lien hypertexte sur facebook? –
Ok, c'est différent. Vous avez donc un lien que vous souhaitez que les utilisateurs puissent partager sur leur profil Facebook? – Julien
Ok, j'ai mis à jour ma question – Julien