Check if user has Facebook Messenger installed iOS 9

前端 未结 4 649
日久生厌
日久生厌 2020-12-17 02:44

Facebook has deprecated the method [FBSDKMessengerSharer messengerPlatformCapabilities] that is used to check if the user has Messenger app installed. In the w

相关标签:
4条回答
  • 2020-12-17 02:53

    You will want to use canOpenURL to see if the Custom URL Scheme fb-messenger:// can be opened. canOpenURL returns a BOOL value indicating whether or not the URL’s scheme can be handled by some app installed on the device. If canOpenURL returns YES then the application is present on the device.

    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb-messenger://"]]) {
        // Installed
        [self.inviteFriendsButton setEnabled:YES];
        [self.inviteFriendsButton setAlpha:1.0];
    }
    else {
        // NOT Installed
        [self.inviteFriendsButton setEnabled:NO];
        [self.inviteFriendsButton setAlpha:0.5];
    }
    

    Also, starting at iOS 9 you must include LSApplicationQueriesSchemes in your info.plist.

    0 讨论(0)
  • 2020-12-17 02:56

    Since the release of the Facebook SDK v4.6.0 they use fb-messenger-api as their URL scheme.

    Swift 2.3

    if UIApplication.sharedApplication().canOpenURL(NSURL(string: "fb-messenger-api://")!) {
        // Installed
    } else {
        // Not installed
    }
    

    Source: https://developers.facebook.com/docs/ios/ios9

    0 讨论(0)
  • 2020-12-17 03:01

    In my case I needed to know whether to show a button users could press to share content on messenger. This worked for my case, and it also checks whether the messenger app is installed.

    -(BOOL) canShareViaMessenger {
        [[[FBSDKMessageDialog alloc] init] canShow]
    }
    
    0 讨论(0)
  • 2020-12-17 03:10

    For those using Swift 3, use this:

    UIApplication.shared.canOpenURL(URL(string: "fb-messenger-api://")!)
    
    0 讨论(0)
提交回复
热议问题