解析Facebook登录错误 - Swift 2

时间:2015-10-04 15:39:19

标签: swift parse-platform ios9 facebook-login

我使用解析服务器创建了一个登录facebook按钮。但是,当单击登录按钮时,我收到如下错误:

  

2015-10-04 18:20:23.040 MyProject [352:91466] *由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [__ NSCFString containsObject:] :无法识别的选择器发送到实例0x15615560'   * 第一次抛出调用堆栈:   (0x22c9b86b 0x3464edff 0x22ca1035 0x22c9ec8f 0x22bce2b8 0x62e355 0x62e1f9 0x1c14dab 0x1c159c1 0x62d5a7 0x61a435 0x61a7f3 0x61a7b5 0x61968d 0x61956f 0x6d5cab 0x6d4e1f 0x6d4ccf 0x49cd08 0x49cf54 0x26de3cc9 0x26de3c55 0x26dcc95b 0x26de35a1 0x26de320f 0x26ddc2d7 0x26dada3d 0x26dac25f 0x22c5e827 0x22c5e417 0x22c5c77f 0x22baf1e9 0x22baefdd 0x2be53af9 0x26e1417d 0x616a74 0x34d79873)   libc ++ abi.dylib:以NSException类型的未捕获异常终止

enter image description here

我正在使用的功能如下所示。我刚刚使用了swift中解析网站中记录的相同方法。为什么我会收到错误?

@IBAction func button_clicked(sender: AnyObject) {

    let permissions = ["public_profile"]

    PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) {
        (user: PFUser?, error: NSError?) -> Void in
        if let user = user {
            if user.isNew {
                print("User signed up and logged in through Facebook!")
            } else {
                print("User logged in through Facebook!")
            }
        } else {
            print("Uh oh. The user cancelled the Facebook login.")
        }
    }
}

我创建了一个桥接标题为

  #import <Parse/Parse.h>

  #import "KeychainWrapper.h"

  #import <FBSDKCoreKit/FBSDKCoreKit.h>

并添加到

   <key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>xxxxxxx</string>
        </array>
    </dict>
</array>
<key>FacebookAppID</key>
<string>xxxxxxxxx</string>
<key>FacebookDisplayName</key>
<string>My App</string>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>facebook.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>fbcdn.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

<key>LSApplicationQueriesSchemes</key>
<string>fbauth2</string>

我的appDelegate是:

import UIKit
import FBSDKCoreKit
import ParseFacebookUtilsV4

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

         Parse.setApplicationId("xxxxxxxxx", clientKey: "xxxxxxxxxxxx")
        PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)

        UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)

        return true
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        FBSDKAppEvents.activateApp()
    }

    func application(application: UIApplication,
        openURL url: NSURL,
        sourceApplication: String?,
        annotation: AnyObject) -> Bool {
            return FBSDKApplicationDelegate.sharedInstance().application(application,
                openURL: url,
                sourceApplication: sourceApplication,
                annotation: annotation)
    }
}

1 个答案:

答案 0 :(得分:0)

我明白了,

我以前的info.plist中的facebook权限代码是字符串,但它必须是数组。

它是:

  <key>LSApplicationQueriesSchemes</key>
   <string>
    <string>fbauth2</string>
   </string>

我将其更新为:

 <key>LSApplicationQueriesSchemes</key>
   <array>
    <string>fbapi</string>
    <string>fbapi20130214</string>
    <string>fbapi20130410</string>
    <string>fbapi20130702</string>
    <string>fbapi20131010</string>
    <string>fbapi20131219</string>
    <string>fbapi20140410</string>
    <string>fbapi20140116</string>
    <string>fbapi20150313</string>
    <string>fbapi20150629</string>
    <string>fbauth</string>
    <string>fbauth2</string>
    <string>fb-messenger-api20140430</string>
   </array>