I\'m trying to open a user\'s Facebook profile in Swift using their Facebook UID. In the Simulator, it works and opens up the web version of the profile and works fine, howe
Here is another solution that works for iOS 10 & Swift 3.
First of all, you should add LSApplicationQueriesSchemes key to Info.plist file. If you do not add this key, canOpenURL will always return false. Than you need to add what scheme(s) you want to check. Use fb for facebook.
It should looks like this:
The rest is Swift:
if UIApplication.shared.canOpenURL(URL(string: "fb://profile/PROFILE_ID")!) {
UIApplication.shared.open(URL(string: "fb://profile/PROFILE_ID")!, options: [:])
} else {
UIApplication.shared.open(URL(string: "https://facebook.com/PROFILE_ID")!, options: [:])
}
Note: Replace PROFILE_ID with your target.