【问题标题】:Error You must initialize PFFacebookUtils错误您必须初始化 PFFacebookUtils
【发布时间】:2016-02-12 15:32:04
【问题描述】:

当我在我的应用程序中调用以下 Objective C 代码时,出现异常。

    [PFFacebookUtils logInInBackgroundWithReadPermissions:permissions block:^(PFUser *user, NSError *error) {
    if (!user) {
        NSLog(@"Uh oh. The user cancelled the Facebook login.");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login Failed"
                                                        message:@"The user cancelled the Facebook login."
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    } else if (user.isNew) {
        NSLog(@"User signed up and logged in through Facebook!");
        [self performSegueWithIdentifier:@"logInSegue" sender:sender];
    } else {
        NSLog(@"User logged in through Facebook!");
        [self performSegueWithIdentifier:@"logInSegue" sender:sender];
    }
}];

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“您必须通过调用 +initializeFacebookWithApplicationLaunchOptions 来初始化 PFFacebookUtils”

下面是用 Swift 编写的 AppDelegate 的代码,我不太确定如何初始化它在 Swift 中的错误中所说的内容?我正在使用最新版本的 Parse,并且在我的 PodFile 中,我有以下 pod 'ParseFacebookUtilsV4' ?有什么想法,请问如何解决这个问题?

    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()

    Parse.setApplicationId(appID, clientKey: clientKey)
    PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)

    let granted: Bool = AppDelegate.IsNotificationPermissionGranted()
    if (granted) {
        AppDelegate.registerNotification()
    }

    //code block from starter project
    PFUser.enableAutomaticUser()

    let defaultACL = PFACL();
    // If you would like all objects to be private by default, remove this line.
    //defaultACL.setPublicReadAccess(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)
        }
    }

    return true
}

【问题讨论】:

    标签: ios iphone xcode facebook parse-platform


    【解决方案1】:

    在 didFinishLaunchingWithOptions 方法中的 AppDelegate 类中添加以下代码

    PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
    

    请注意,您可能需要先导入 ParseFacebookUtilsV4。

    【讨论】:

    • 谢谢你,Ivan,我试过了,但后来删除了那行代码,因为它无法识别 PFFacebookUtils,因为愚蠢的我忘了导入 ParseFacebookUtilsV4
    猜你喜欢
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 2011-05-18
    相关资源
    最近更新 更多