1

我正在使用FBSDKLoginManager接收令牌以供以后使用(FB发布),并在确认访问后进入无限循环。

调用 时FBSDKLoginManager(),会出现以下弹窗(对不起,它是德语……这是官方的 Facebook 弹窗,用户可以在其中选择是手动登录还是使用 FB App 登录)。

Facebook 弹出屏幕

现在出现以下错误:

  • 如果我使用第二个按钮(通过电话号码或电子邮件地址登录),一切正常。该函数返回一个令牌,我可以在我的应用程序中继续。

  • 错误:如果我使用第一个按钮(使用 Facebook 应用程序登录),Facebook 应用程序打开,我可以在 FB 中设置所有隐私设置,并确认。确认访问后,FB-App 将自动关闭并返回相同的弹出屏幕,无需任何更改。返回此屏幕后没有任何动作...

我不知道问题出在哪里......没有错误消息。由于使用电子邮件登录时一切正常,因此问题一定出在 FB-App 的返回上。电子邮件登录通过 Safari 工作,在错误情况下,FB-App 会中断。

let login: FBSDKLoginManager = FBSDKLoginManager()
login.logIn(withPublishPermissions: ["publish_actions"], from: self) { (result, error) in
if (error != nil) {
    print("publish_actions: \(error!)")
} else if (result?.isCancelled)! {
    print("publish_actions: Canceled")
} else if (result?.grantedPermissions.contains("publish_actions"))! {
    //print("publish_actions: permissions granted: \(String(describing: result?.token.tokenString))")

    UserDefaults.standard.set(result?.token.tokenString, forKey: "facebook_token")
}

添加的框架:Bolts / CoreKit / LoginKit

开发环境: Xcode 9.2 / iPhone 6s 安装 iOS 11.2 / 最新 Facebook 应用程序。

4

4 回答 4

1

我通过将以下缺少的调用添加到 FB SDK 来解决:

[[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];

里面

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotationAppDelegate 的方法。

于 2018-05-27T08:33:52.333 回答
0

检查您的信息 plist 文件中的以下内容

<key>FacebookAppID</key>
<string>fb_id_here</string> // in format 234234234
<key>FacebookDisplayName</key>
<string>display_name_here</string>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>

</array>
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fbfb_id_here </string>. // in format fb234234234
        </array>
    </dict>
</array>

现在在你的应用程序中

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

func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {

    if let scheme = url.scheme {

        if scheme == "fb 234234234" { //the one you kept in your info plist file
            //TODO: replace with real value
            return SDKApplicationDelegate.shared.application(application, open: url, options: options)
        }

    }

    return true

}

配置这些,然后配音你的应用程序,如果控制folw进入appdelegate函数

func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool

如果不是,您没有在 info plist 文件中正确配置 facebook 架构

let fbManager = FBSDKLoginManager()
fbManager.logOut()

    let readPermissions: [ReadPermission] = [.publicProfile, .email]
    let sdkPermissions = readPermissions.map({ $0.permissionValue.name })

    fbManager.logIn(withReadPermissions: sdkPermissions, from: nil) { (result, error) in
        if let token = result?.token {
            // your token here
        }
        else {
        }
    }
于 2018-03-08T07:24:44.877 回答
0

非常感谢。这解决了问题。

1.) plist 文件已经建立。我认为否则使用 Safari 登录将无法正常工作。

2.) App Delegate 是原因!!!小调整:

SDKApplicationDelegate.shared没用。我应该如下:

FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

(以及添加的“应用程序打开 URL”功能。)

但现在它起作用了。非常感谢。

于 2018-03-08T11:15:15.203 回答
-1

我想也许我发现了一个问题,在我的 xcode、AppDelegate 中 ,func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Boolxcode 将此函数修复privateinternal

于 2019-01-21T10:24:58.063 回答