首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误,必须初始化PFFacebookUtils。

错误,必须初始化PFFacebookUtils。
EN

Stack Overflow用户
提问于 2016-02-12 15:32:04
回答 1查看 244关注 0票数 1

当我在我的应用程序中调用下面的目标C代码时,我会得到一个异常。

代码语言:javascript
复制
    [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];
    }
}];

终止应用程序的原因是:“您必须通过调用+initializeFacebookWithApplicationLaunchOptions‘初始化PFFacebookUtils

下面是AppDelegate用Swift编写的代码,我不太确定如何初始化它在Swift错误中的内容?我正在使用最新版本的Parse,也在我的PodFile中,我有下面的pod 'ParseFacebookUtilsV4‘?知道吗,请怎么解决这个?

代码语言:javascript
复制
    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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-13 14:06:16

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

代码语言:javascript
复制
PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35366379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档