5

Currently, I want to check in my app whether Facebook App is installed or not.

What am I doing:

UIApplication.shared.canOpenURL(URL(string: "fb://")!)enter code here

In URL Schemes I have added fb, so not missed that part too.

But canOpenURL RETURNS TRUE ! But the app IS UNinstalled. I restarted the device, not helped. Why this is happening? UPDATE: some code

if UIApplication.shared.canOpenURL(URL(string: "fb://")!) {
    self.shareToFacebook(with: completion)
} else {
    progressVC.dismiss(animated: false, completion: nil)
    UIApplication.shared.open(URL(string: "https://itunes.apple.com/us/app/facebook/id284882215")!)
}

SOLUTION: I found the solution people. In URL types I had been added fb45....(id of my app), and also added fb, which one shouldn't be there, I removed fb, and only kept the one with id, so the openURL now returns false if the app is not installed

kawake123
  • 53
  • 8
  • if you added that to url schemes app can open, what else do you want it to do? – Lu_ Aug 10 '17 at 07:43
  • Lu_ I want to handle case when Facebook App is not installed, but I get true everytime, even if the app is UNINSTALLED – kawake123 Aug 10 '17 at 07:46
  • and what happens then when app is uninstalled? everything is going like it should – Lu_ Aug 10 '17 at 07:51
  • Lu_ it's trying to share to Facebook, but the app is uninstalled, but I need to redirect the user to App Store – kawake123 Aug 10 '17 at 08:14

1 Answers1

10

You need to add fb to the LSApplicationQueriesSchemes array in the app plist, not the URL schemes array, like so:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fb</string>
</array>
pckill
  • 3,709
  • 36
  • 48