PFFacebookUtils.initializeFacebookWithApplicationL

2019-01-15 21:29发布

问题:

I'm trying to integrate facebook login in my parse application. I followed every step mentioned in parse tutorial. In the below code, I'm getting compilation error.

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    line1: Parse.setApplicationId("xxx", clientKey: "yyy")
    line2: PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)       
    line3: PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
    line4: return true
}

In line 3, I'm getting error:

Value of optional type '[NSObject:AnyObject]' not unwrapped; did you mean to use '!' or '?'?

If I manually unwrap it using '!', because launchOptions can be nil, I get:

Fatal error: unexpectedly found nil while unwrapping an Optional value

If I check for nil, I get:

NSInternalInconsistencyException', reason: 'You must initialize PFFacebookUtils with a call to +initializeFacebookWithApplicationLaunchOptions

Any idea how to fix it?

回答1:

It is a bug in ParseSDK. Until Parse fix this you can change the initialize function declaration at PFFacebookUtils.h header file

1) Go to PFFacebookUtils.h

2) change:

  • (void)initializeFacebookWithApplicationLaunchOptions:(NSDictionary *)launchOptions;

To:

  • (void)initializeFacebookWithApplicationLaunchOptions:(PF_NULLABLE NSDictionary *)launchOptions;

This answer was provided by Kiarash Akhlaghi at https://developers.facebook.com/bugs/1462780714012820/



回答2:

The problem was a bug of ParseSDK, it does not accept nil launchOptions

According to the the answer provided by Roger Ingouacka at https://developers.facebook.com/bugs/1462780714012820/

    if let launchOptions = launchOptions {
        PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
    } else {
        PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions([NSObject:AnyObject]())
    }

Notice the use of

[NSObject:AnyObject]()



回答3:

This problem persisted untill I updated to Parse library 1.8.1.

I tried adjusting PFFacebookUtils.h, and a lot of other things, but that did not solve it. It was driving me insane.