简体   繁体   中英

Open link in Facebook app if available

I want to open a page in the Facebook app if the user has it installed on his device.
Now, I am using the following code I found while doing research:

let myUrl = NSURL(string: "fb://profile/myPage'sID")!
if UIApplication.sharedApplication().canOpenURL(myUrl) {
    UIApplication.sharedApplication().openURL(myUrl)
} else {
    UIApplication.sharedApplication().openURL(NSURL(string: "https://www.facebook.com/myPage")!)
}

This does work for a profile but does not for displaying a page .
(Note that both IDs do work, as I tested them.)

Any ideas?
Thanks in advance :)

I think then it may be caused because you need to add this key-value to the Info.plist:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fb</string>
</array>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM