FBSDKLoginManager logInWithReadPermissions:fromViewController:handler:]:无法识别的选择器发送到实例0x7fed38d61290

时间:2016-03-20 03:45:37

标签: facebook heroku swift2 ios9 xcode7

似乎无法解决此问题。我进入并删除了所有parse和fb SDK,然后下载了最新的解析和fb SDK并投入到项目中。

日志中仍然出现此错误。甚至不到fb屏幕。 如果你能提供帮助,下面是我的代码。我已经研究了这个问题的所有实例,但还没有解决。我错过了什么。

AppDelegate.swift:

导入UIKit 导入Parse 导入ParseFacebookUtilsV4 进口螺栓

//如果要使用任何UI组件,请取消注释此行 //导入ParseUI

//如果您要使用崩溃报告,请取消注释此行 //导入ParseCrashReporting

@UIApplicationMain class AppDelegate:UIResponder,UIApplicationDelegate {

var window: UIWindow?

//--------------------------------------
// MARK: - UIApplicationDelegate
//--------------------------------------

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Enable storing and querying data from Local Datastore. 
    // Remove this line if you don't want to use Local Datastore features or want to use cachePolicy.
    Parse.enableLocalDatastore()

    let parseConfiguration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in
        ParseMutableClientConfiguration.applicationId = "xxx"
        ParseMutableClientConfiguration.clientKey = "xxx"
        ParseMutableClientConfiguration.server = "https://yourapp.herokuapp.com/parse"
    })

    Parse.initializeWithConfiguration(parseConfiguration)

    PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)

    PFUser.enableAutomaticUser()

    let defaultACL = PFACL();

    // If you would like all objects to be private by default, remove this line.
    defaultACL.publicReadAccess = true

    PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser:true)

    if application.applicationState != UIApplicationState.Background {
        // Track an app open here if we launch with a push, unless
        // "content_available" was used to trigger a background push (introduced in iOS 7).
        // In that case, we skip tracking here to avoid double counting the app-open.

        let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
        let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
        var noPushPayload = false;
        if let options = launchOptions {
            noPushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil;
        }
        if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) {
            PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
        }
    }

    if application.respondsToSelector("registerUserNotificationSettings:") {
        let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)



        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()
    } else {
        let types: UIRemoteNotificationType = [UIRemoteNotificationType.Badge, UIRemoteNotificationType.Alert, UIRemoteNotificationType.Sound]
        application.registerForRemoteNotificationTypes(types)
    }

    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

//--------------------------------------
// MARK: Push Notifications
//--------------------------------------

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    let installation = PFInstallation.currentInstallation()
    installation.setDeviceTokenFromData(deviceToken)
    installation.saveInBackground()

    PFPush.subscribeToChannelInBackground("") { (succeeded, error) in
        if succeeded {
            print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.");
        } else {
            print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.", error)
        }
    }
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    if error.code == 3010 {
        print("Push notifications are not supported in the iOS Simulator.")
    } else {
        print("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
    }
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    PFPush.handlePush(userInfo)
    if application.applicationState == UIApplicationState.Inactive {
        PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
    }
}

func application(application: UIApplication,
    openURL url: NSURL,
    sourceApplication: String?,
    annotation: AnyObject) -> Bool {

    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
        FBSDKAppEvents.activateApp()
}   

}

ViewController.swift:

导入UIKit 导入Parse 导入FBSDKCoreKit 导入FBSDKLoginKit 导入ParseFacebookUtilsV4

类ViewController:UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()


    // array of what we want to get from the fb user account
    let permissions = ["public_profile"]

    PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) {
        (user: PFUser?, error: NSError?) -> Void in

        if let error = error { // if error exists

            print(error)

        } else {

            if let user = user { // if user exists

                print(user)
            }
        }
    }

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

0 个答案:

没有答案