简体   繁体   中英

PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions) giving compilation error

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?

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/

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM