ios - 检查用户是否安装了 Facebook Messenger iOS 9

标签 ios facebook ios9 messenger

Facebook 已弃用用于检查用户是否安装了 Messenger 应用程序的方法 [FBSDKMessengerSharer messengerPlatformCapabilities]。在警告消息中,它说:

messengerPlatformCapabilities is deprecated: This is deprecated as of iOS 9. If you use this, you must configure your plist as described in https://developers.facebook.com/docs/ios/ios9

我想删除此方法,但还没有找到任何其他选项来替换此代码(如果用户未安装 Messenger 应用程序,该按钮将被禁用):

if (![FBSDKMessengerSharer messengerPlatformCapabilities]) {
    [self.inviteFriendsButton setEnabled:NO];
    [self.inviteFriendsButton setAlpha:0.5f];
}

还有其他方法吗?或者,作为新的 iOS 要求,我应该避免使用此 if?先感谢您。

最佳答案

您需要使用 canOpenURL 来查看自定义 URL 方案 fb-messenger:// 是否可以打开。 canOpenURL 返回一个 BOOL 值,指示 URL 的方案是否可以由安装在设备上的某些应用处理。如果 canOpenURL 返回 YES,则应用程序存在于设备上。

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];
}

此外,从 iOS 9 开始,您必须在 info.plist 中包含 LSApplicationQueriesSchemes

enter image description here

关于ios - 检查用户是否安装了 Facebook Messenger iOS 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32713306/

相关文章:

facebook - 用户如何评价 Facebook Connect 网站?

iphone - 如何在 iPhone sdk 中更改 Facebook 语言?

ios - UICollectionView cellForItemAtIndexPath 上的 Swift 专门崩溃

ios - 在导航栏中添加图像

objective-c - 在不删除 MKAnnotation 的情况下更改 MKAnnotation View

ios - 同时使用 AVCaptureMovieFileOutput 和 AVCaptureVideoDataOutput 委托(delegate)方法

iPhone 4 AVFoundation : Capture from front and rear cameras simultaneously

api - 我可以使用 Facebook 的 API "add friend"吗?

iOS 9 - 键盘在升级时将包名称显示为 "(null)"

ios9 - 在没有 Apple Developer Program (Xcode 7) 的情况下在 iOS 上安装应用程序