1
class func openFacebook(id: String){ //id is a username in this case
    let name = id.replace(" ", withString: "")
    let hook = "fb://profile/" + name
    let hookURL = NSURL(string: hook)
    if UIApplication.sharedApplication().canOpenURL(hookURL!){
        UIApplication.sharedApplication().openURL(hookURL!)
    } else {
        UIApplication.sharedApplication().openURL(NSURL(string: "http://facebook.com/" + name)!)
    }
}

I try to do this, but it never opens the app. It always opens the browser. I'm not using the facebook sdk. I just want to open facebook from my app, to the user's profile.

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
  • Any messages in the console when you run this code? Did you add the `fb` scheme to the list of allowable schemes your app can access? – rmaddy Oct 07 '16 at 02:32
  • No, I didn't add fb scheme to list of allowable schemes. However, I also have similar code for instagram/twitter -- and those work, and I didn't add those to plist either. – TIMEX Oct 07 '16 at 02:35
  • They won't work under iOS 9 or later. – rmaddy Oct 07 '16 at 02:36
  • I'm on iOS 10, and every scheme works except for fb. – TIMEX Oct 07 '16 at 02:42
  • [This](http://stackoverflow.com/questions/38689631/how-to-use-facebook-ios-sdk-on-ios-10) post might help you. – Rashwan L Oct 07 '16 at 03:09

2 Answers2

7

The iOS URL schema goes like this:

fb://profile?id=[username|user_id]
Tamas Rev
  • 7,008
  • 5
  • 32
  • 49
RamyRGB
  • 71
  • 2
  • 4
1

If you have an error: 'LSApplicationQueriesSchemes' so you have to register url scheme in LSApplicationQueriesSchemes under plist.

please check below link for process of adding url scheme to LSApplicationQueriesSchemes.

Facebook SDK: app not registered as a URL Scheme

Community
  • 1
  • 1
KKRocks
  • 8,222
  • 1
  • 18
  • 84