Facebook SDK 在 Swift 2 iOS 9 中登录时出错。

16

我试图在iOS 9和Swift 2中使用Facebook SDK制作一个简单的Facebook登录,但它总是抛出一个错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString containsObject:]: unrecognized selector sent to instance 0xa326874756162667'

这发生在usr/include/dispatch/once.h中,我无法独自解决它。有人有什么想法吗?

代码在此处:

import FBSDKCoreKit
import FBSDKLoginKit


let loginManager = FBSDKLoginManager()
loginManager.logInWithReadPermissions(["basic_info", "email", "user_likes"], fromViewController: self.parentViewController, handler: { (result, error) -> Void in
    if error != nil {
        print(FBSDKAccessToken.currentAccessToken())
    } else if result.isCancelled {
        print("Cancelled")
    } else {
        print("LoggedIn")
    }
})

更新:以下是完整的错误堆栈:

2015-10-02 13:40:33.884 FacyNews[24902:1352812] -[NSTaggedPointerString containsObject:]: unrecognized selector sent to instance 0xa326874756162667
2015-10-02 13:40:33.889 FacyNews[24902:1352812] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString containsObject:]: unrecognized selector sent to instance 0xa326874756162667'
*** First throw call stack:
(
 0   CoreFoundation                      0x000000010dbe8f65 __exceptionPreprocess + 165
 1   libobjc.A.dylib                     0x000000010f87adeb objc_exception_throw + 48
 2   CoreFoundation                      0x000000010dbf158d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
 3   CoreFoundation                      0x000000010db3ef7a ___forwarding___ + 970
 4   CoreFoundation                      0x000000010db3eb28 _CF_forwarding_prep_0 + 120
 5   FBSDKCoreKit                        0x000000010d52ea8b +[FBSDKInternalUtility isRegisteredCanOpenURLScheme:] + 171
 6   FBSDKCoreKit                        0x000000010d52e8da +[FBSDKInternalUtility checkRegisteredCanOpenURLScheme:] + 362
 7   FBSDKCoreKit                        0x000000010d52d0ed __46+[FBSDKInternalUtility isFacebookAppInstalled]_block_invoke + 45
 8   libdispatch.dylib                   0x0000000110ded49b _dispatch_client_callout + 8
 9   libdispatch.dylib                   0x0000000110dd8e28 dispatch_once_f + 543
 10  FBSDKCoreKit                        0x000000010d52cff7 +[FBSDKInternalUtility isFacebookAppInstalled] + 87
 11  FBSDKLoginKit                       0x000000010d6d6cb1 -[FBSDKLoginManager logInParametersWithPermissions:] + 449
 12  FBSDKLoginKit                       0x000000010d6d7358 -[FBSDKLoginManager logInWithBehavior:] + 88
 13  FBSDKLoginKit                       0x000000010d6d72d4 -[FBSDKLoginManager logInWithPermissions:handler:] + 292
 14  FBSDKLoginKit                       0x000000010d6d55e7 -[FBSDKLoginManager logInWithReadPermissions:fromViewController:handler:] + 343
 15  FacyNews                            0x000000010d3a2e5c _TFFC8FacyNews20MasterViewController14viewWillAppearFS0_FSbT_U_FCSo13UIAlertActionT_ + 700
 16  FacyNews                            0x000000010d3a3297 _TTRXFo_oCSo13UIAlertAction_dT__XFo_iS__iT__ + 23
 17  FacyNews                            0x000000010d39e131 _TPA__TTRXFo_oCSo13UIAlertAction_dT__XFo_iS__iT__ + 81
 18  FacyNews                            0x000000010d3a2b40 _TTRXFo_iCSo13UIAlertAction_iT__XFo_oS__dT__ + 32
 19  FacyNews                            0x000000010d3a2b8c _TTRXFo_oCSo13UIAlertAction_dT__XFdCb_dS__dT__ + 60
 20  UIKit                               0x000000010e709fa5 -[UIAlertController _fireOffActionOnTargetIfValidForAction:] + 96
 21  UIKit                               0x000000010e70a785 __85-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:]_block_invoke + 30
 22  UIKit                               0x000000010e55fc9f -[UIPresentationController transitionDidFinish:] + 1248
 23  UIKit                               0x000000010e563210 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
 24  UIKit                               0x000000010edb31e9 -[_UIViewControllerTransitionContext completeTransition:] + 101
 25  UIKit                               0x000000010e4a9daa -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 644
 26  UIKit                               0x000000010e4883a7 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 241
 27  UIKit                               0x000000010e488756 -[UIViewAnimationState animationDidStop:finished:] + 80
 28  QuartzCore                          0x00000001135e8d70 _ZN2CA5Layer23run_animation_callbacksEPv + 308
 29  libdispatch.dylib                   0x0000000110ded49b _dispatch_client_callout + 8
 30  libdispatch.dylib                   0x0000000110dd534b _dispatch_main_queue_callback_4CF + 1738
 31  CoreFoundation                      0x000000010db493e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
 32  CoreFoundation                      0x000000010db0a939 __CFRunLoopRun + 2073
 33  CoreFoundation                      0x000000010db09e98 CFRunLoopRunSpecific + 488
 34  GraphicsServices                    0x00000001130a2ad2 GSEventRunModal + 161
 35  UIKit                               0x000000010e403676 UIApplicationMain + 171
 36  FacyNews                            0x000000010d39959d main + 109
 37  libdyld.dylib                       0x0000000110e2192d start + 1
 38  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

提前致谢。


дҪ жҳҜеҗҰеңЁinfo.plistдёӯж·»еҠ дәҶLSApplicationQueriesSchemesе…ій”®еӯ—пјҹиҜ·жҹҘзңӢжӯӨзӯ”жЎҲпјҡhttps://dev59.com/questions/tl0Z5IYBdhLWcg3w3DUW#32441523пјҢе…¶дёӯеұ•зӨәдәҶеҗ„з§ҚзӨҫдәӨзҪ‘з»ңеә”иҜҘеҰӮдҪ•й…ҚзҪ®гҖӮ - ChrisH
@ChrisH 是的,我添加了,但是当我回答时,我添加的方式不正确,SDK没有检查它是否是一个字符串数组。 - Gabriel
@Gabriel,你能发一下可用的代码吗?我在使用Swift 2.0时也遇到了问题。 - Saty
3个回答

23

我已经解决了这个问题。虽然文档中没有提到LSApplicationQueriesSchemes,但是我收到了缺少该项的错误消息。我将键和值“fbauth2”写入info.plist作为字符串,但它实际上是一个数组,而SDK在获取字符串数组的元素时没有进行任何检查。

不过,感谢大家提供的帮助回答。


非常感谢! - AsTeR

4

请查看链接,了解如何在iOS9中集成FacebookSDK时将“fbauth2”添加到.plist

FYI,我遇到了以下崩溃信息:

*** Terminating app due to uncaught exception 'InvalidOperationException', reason: 'fbauth2 is missing from your Info.plist under LSApplicationQueriesSchemes and is required for iOS 9.0'
*** First throw call stack:

通过在.plist中添加以下内容解决了它。

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>

-1

我认为你的错误不在你发布的代码中。但是尝试删除"basic_info"权限,因为它已经被弃用,在iOS 9中可能会产生一些意外的值。

你可以阅读这个:

"以前,basic_info是一个必须要请求的权限,并暗示了public_profile和user_friends。随着新的Facebook登录,basic_info现在已经被弃用,不应该再请求。相反,明确地请求public_profile和user_friends(如果需要)."

这里


谢谢,这会有所帮助,但问题仍然存在。 - Gabriel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接