Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add hyperlink in iPhone app?

In my iPhone app, I require to show the hyperlink to a website

How can I add hyperlink for a website in iPhone programming?.

Actually i want to pass the link from my app onto facebook using facebook API.

So how should I format my text such that it works as hyperlink on facebook?

I am still stuck with this issue.

like image 632
Parth Bhatt Avatar asked Dec 10 '10 09:12

Parth Bhatt


People also ask

How do I add a hyperlink in email on iPhone app?

Open your Mail app and start a new email, then copy the URL that you want to hyperlink by navigating to it in Safari and long pressing the URL until the copy option pops up. Tap on it. Now paste it into your email by tapping in the whitespace and selecting "paste." Move your cursor anywhere within the URL text.

How do I send a link to an app on my iPhone?

On your iOS device, you can share an app directly from the App Store by finding and clicking on the application you want, then scrolling down to "Tell a Friend" which lets you send an email with a link to the application.


1 Answers

It depends on where you want to put this link. If it is in a UITextView, you just have to enable it.

textView.text = @"Some text with link in it : http://http://stackoverflow.com";
textView.dataDetectorTypes = UIDataDetectorTypeLink;

More info on iOS reference library.

Or, if you want to open Safari programmatically:

NSURL *url = [ [ NSURL alloc ] initWithString: @"http://stackoverflow.com" ];
[[UIApplication sharedApplication] openURL:url];
[url release];

If you want to share on Facebook, you need to tell Safari to open a URL which will display a Facebook page that allows the user to share. Here is an example:

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
like image 134
Julien Avatar answered Oct 23 '22 16:10

Julien