我按照说明执行了here,但我无法执行连接应用程序委派的步骤5,因为说明在Objective C中,而我的应用程序委派文件是用Swift编写的。
我试过这个:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    // Add any custom logic here.
    return true
}

func application(_ application: UIApplication, open url: URL, options: (UIApplicationOpenURLOptionsKey & id)) -> Bool {
    let handled: Bool = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey], annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
    // Add any custom logic here.
    return handled
}

导致此生成错误的:
The following build commands failed:
    CompileSwift normal x86_64 /Users/kevinchiang/jh-mobile/ios/JustHive/Appdelegate.swift
    CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)

我不熟悉Swift和Obj-C,所以我认为我的Swift代码可能有问题。

最佳答案

在您的函数中,参数选项的类型是“cc>”,它不存在,您应该在SWIFT中查找它的等价物,这是一个“AA>”,如您所见,“AA>是一个包含多个元素以正确使用FB SDK的字典,您必须使用对应于选项注释和选项源的键。应用程序,以便您可以正确使用它。
所以回答你的问题应该改变你的第二个功能。告诉我进展如何。

func application(_ app: UIApplication,
              open url: URL,
               options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool{
    let handled: Bool = FBSDKApplicationDelegate.sharedInstance().application(applic‌​ation, openURL: url, sourceApplication: options[.sourceApplication], annotation: options[.annotation])
    return handled
}

您还可以简化上面的代码,删除变量句柄,它将如下所示。
func application(_ app: UIApplication,
              open url: URL,
               options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool{

    return FBSDKApplicationDelegate.sharedInstance().application(applic‌​ation, openURL: url, sourceApplication: options[.sourceApplication], annotation: options[.annotation])

}

09-25 20:07
查看更多