Integration new facebook SDK by swift

前端 未结 11 1500
情书的邮戳
情书的邮戳 2020-12-23 09:59

Today i tried to integrate facebook SDK to my Swift app but in the quick start on facebook guide page looks a bit different than my old code. How can i convert OBJ-C code be

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 10:39

    On iOS 9 you should be using:

    func application(application: UIApplication,openURL url: NSURL, options: [String: AnyObject]) -> Bool {
       return ApplicationDelegate.shared.application(application, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String, annotation: annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
    }
    

    I found the potential for the Application delegate to break in iOS 9 with the annotation: options[UIApplicationOpenURLOptionsAnnotationKey] as it will not accept nil values. You can set this to a blank string and the application should run fine with facebook after this.

    Swift 2.2 docs:

    You specify optional chaining by placing a question mark (?) after the optional value on which you wish to call a property, method or subscript if the optional is non-nil. This is very similar to placing an exclamation mark (!) after an optional value to force the unwrapping of its value. The main difference is that optional chaining fails gracefully when the optional is nil, whereas forced unwrapping triggers a runtime error when the optional is nil.

提交回复
热议问题