简体   繁体   中英

How to open facebook page in native iOS app

I want to open facebook native app and direct user to my facebook's page if app is installed on the user's device. Following code doesn't work, it always opens browser.

Page ID 1234 is just for example, I've used my page's read Page ID so I'm passing correct ID in my actual code.

How to fix it?

if UIApplication.shared.canOpenURL(URL(string: "fb://profile/1234")!) {
    UIApplication.shared.open(URL(string: "fb://profile/1234")!, options: [:], completionHandler: nil)
} else {
    UIApplication.shared.open(URL(string: "https://facebook.com/pageurl")!, options: [:], completionHandler: nil)
}

Following needs to be added in info.plist for above code to work.

<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