Parth Bhatt Parth Bhatt - 1 year ago 145
Objective-C Question

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.

Answer Source

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

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

More info on iOS reference library

Or if you want to open Safari programatically :

NSURL *url = [ [ NSURL alloc ] initWithString: @"" ];
[[UIApplication sharedApplication] openURL:url];
[url release];

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

NSString *urlString = @"";
//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:@"", 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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download