Take the 2-minute tour ×

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.

Please Help and Suggest


share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

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://http://stackoverflow.com";
textView.dataDetectorTypes = UIDataDetectorTypeLink;

More info on iOS reference library

Or if you want to open Safari programatically :

NSURL *url = [ [ NSURL alloc ] initWithString: @"http://stackoverflow.com" ];
[[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 = @"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
share|improve this answer
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? –  Parth Bhatt Dec 10 '10 at 10:35
Ok, that's different. So you have a link you want users to be able to share on their Facebook profile ? –  Julien Dec 10 '10 at 16:55
Ok, I updated my question –  Julien Dec 10 '10 at 17:04
Isn't it answering your question ? –  Julien Dec 11 '10 at 19:31
@Julien: Sorry I forgot to tick your answer as an answer. Really Sorry for that :) –  Parth Bhatt Mar 23 '11 at 14:16
show 3 more comments

My favorite library for sharing would be ShareKit. It's really easy to setup in your app, and will allow people to share via Facebook, and other services too. It's customizable too, so you can skin it, change colors, and control which services you want users to share with.

Check out, http://www.getsharekit.com/

Once you add it to your app you can integrate it very easily by creating a button

[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction

//add the button to a navigation bar or tool bar.

and then creating the share method in your controller.

- (void)share
    NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];

    // Get the ShareKit action sheet
    SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

    // Display the action sheet
    [actionSheet showFromToolbar:navigationController.toolbar];
share|improve this answer
add comment


Can you mention where you need to insert hyperlink ,this is my way to insert link in iPhone app:

         NSMutableString *err=[[NSMutableString alloc] init];
        [err appendString:@"<html><body style=\"background-color:black\" ><font size=3 face=\"helvetica\" color=\"white\" align=\"center\"><H3>Login Error</H3><p> "];
        [err appendString:@"Please try again. If you forgot your password, you can retrieve it at<a href=\"ENTER YOUR LINK URL\"><font color=\"red\"> ENTER LINK TEXT</font></a>.</font></p></body></html>"];
share|improve this answer
add comment

Your Answer


