PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions) giving compilation error

╄→尐↘猪︶ㄣ 提交于 2019-11-26 22:09:31

问题


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.



来源:https://stackoverflow.com/questions/29727608/pffacebookutils-initializefacebookwithapplicationlaunchoptionslaunchoptions-gi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!