20

我为 Facebook 登录安装了两个 pod

pod 'FacebookCore'
pod 'FacebookLogin'

比在 appdelegate 中导入 FacebookCore。它仍然显示使用未解决的标识符错误。

未解决的标识符错误

我还在 info.plist 中实现了标签

<array>
<string>fb---------</string>
</array>
<key>FacebookAppID</key>
<string>-----------</string>
<key>FacebookDisplayName</key>
<string>-----------</string>

仍然无法获取 SDKApplicationDelegate。

func application(_ app: UIApplication, open url: URL,
                 options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
    if SDKApplicationDelegate.shared.application(app, open: url, options: options) {
        return true
    }
    return false
}
4

3 回答 3

42

因为SDKApplicationDelegate改成ApplicationDelegate

func application(_ app: UIApplication, open url: URL,
                 options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
    if ApplicationDelegate.shared.application(app, open: url, options: options) {
        return true
    }
    return false
}

还有一件事要做

class AppDelegate: UIResponder, UIApplicationDelegate

同时导入这两个 pod

import FBSDKCoreKit
import FBSDKLoginKit 
于 2019-05-15T08:59:05.677 回答
12

细节

  • Xcode 版本 10.3 (10G8)
  • 斯威夫特 5
  • FacebookCore (0.7.0)

解决方案

只需替换SDKApplicationDelegateApplicationDelegate

代码

import FacebookCore

//....

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)

    return true
}

//....

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
    guard let urlScheme = url.scheme else { return false }
    if urlScheme.hasPrefix("fb") {
        return ApplicationDelegate.shared.application(app, open: url, options: options)
    }
    return true
}
于 2019-07-23T19:03:37.450 回答
1

为了能够让facebook登录添加这两种方法

func application(_ app: UIApplication,open url: URL,options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool{

    if #available(iOS 9.0, *) {
        let sourceApplication: String? = options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String
        return FBSDKApplicationDelegate.sharedInstance().application(app, open: url,sourceApplication: sourceApplication, annotation: nil)
    }

    return true
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {

    return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL?, sourceApplication: sourceApplication, annotation: annotation)
}

import FBSDKCoreKit

import FBSDKLoginKit
于 2019-05-15T09:04:42.163 回答