Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know the question is old, but in support of the above answers i wanted to share my working code. Just add these two methods to whatever class.The code checks if facebook app is installed, if not installed the url is opened in a browser.And if any errors occur when trying to find the profileId, the page will be opened in a browser. Just pass the url(example, <a href="http://www.facebook.com/AlibabaUS" rel="noreferrer">http://www.facebook.com/AlibabaUS</a>) to openUrl: and it will do all the magic. Hope it helps someone!.</p> <blockquote> <p>NOTE: UrlUtils was the class that had the code for me, you might have to change it to something else to suite your needs.</p> </blockquote> <pre><code>+(void) openUrlInBrowser:(NSString *) url { if (url.length &gt; 0) { NSURL *linkUrl = [NSURL URLWithString:url]; [[UIApplication sharedApplication] openURL:linkUrl]; } } +(void) openUrl:(NSString *) urlString { //check if facebook app exists if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) { // Facebook app installed NSArray *tokens = [urlString componentsSeparatedByString:@"/"]; NSString *profileName = [tokens lastObject]; //call graph api NSURL *apiUrl = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@",profileName]]; NSData *apiResponse = [NSData dataWithContentsOfURL:apiUrl]; NSError *error = nil; NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:apiResponse options:NSJSONReadingMutableContainers error:&amp;error]; //check for parse error if (error == nil) { NSString *profileId = [jsonDict objectForKey:@"id"]; if (profileId.length &gt; 0) {//make sure id key is actually available NSURL *fbUrl = [NSURL URLWithString:[NSString stringWithFormat:@"fb://profile/%@",profileId]]; [[UIApplication sharedApplication] openURL:fbUrl]; } else{ [UrlUtils openUrlInBrowser:urlString]; } } else{//parse error occured [UrlUtils openUrlInBrowser:urlString]; } } else{//facebook app not installed [UrlUtils openUrlInBrowser:urlString]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload