Facebook SDK使用Swift 3 iOS 10登录 [英] Facebook SDK sign in with Swift 3 iOS 10

查看:276
本文介绍了Facebook SDK使用Swift 3 iOS 10登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过Cocoapods安装了Facebook的Swift SDK:

I installed Facebook's Swift SDK via Cocoapods:

pod 'FacebookCore', :git => "https://github.com/facebook/facebook-sdk-swift"
pod 'FacebookLogin', :git => "https://github.com/facebook/facebook-sdk-swift"

我已经按照来自Facebook的Swift SDK的登录说明( https://developers.facebook.com/docs/swift/login ),但无法使其正常工作。

I have followed the login instructions from Facebook's Swift SDK (https://developers.facebook.com/docs/swift/login) but cannot get it working.

在我的视图控制器内,我有以下内容:

Inside my view controller I have the following:

@objc fileprivate func facebookSignIn() {
    let loginManager = LoginManager()
    print("LOGIN MANAGER: \(loginManager)")
    loginManager.logIn([ .publicProfile, .email ], viewController: self) { loginResult in
        print("LOGIN RESULT! \(loginResult)")
        switch loginResult {
        case .failed(let error):
            print("FACEBOOK LOGIN FAILED: \(error)")
        case .cancelled:
            print("User cancelled login.")
        case .success(let grantedPermissions, let declinedPermissions, let accessToken):
            print("Logged in!")
            print("GRANTED PERMISSIONS: \(grantedPermissions)")
            print("DECLINED PERMISSIONS: \(declinedPermissions)")
            print("ACCESS TOKEN \(accessToken)")
        }
    }
}

登录管理员等当我点击按钮打开网页视图打开。我可以通过Facebook登录,然后网页浏览空白,没有任何反应。该应用程序显示在我的Facebook应用程序,所以有一些授权已经发生,但是如果我点击网页视图中的完成按钮,回调的结果是 .cancelled 和用户取消登录。已经打印。

"Login manager: etc." prints when I click the button and the web view opens. I can sign in via Facebook and then the web view goes blank and nothing happens. The app shows in my Facebook apps, so some authorisation has taken place, but if I click the "Done" button in the web view, the result to the callback is .cancelled and "User cancelled login." is printed.

我已经将钥匙串共享添加到我的权利,我更新了我的info.plist:

I have added Keychain Sharing to my entitlements, and I've updated my info.plist:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string> [ FB STRING ] </string>
        </array>
    </dict>
</array>
<key>FacebookAppID</key>
<string>[ APP ID ]</string>
<key>FacebookDisplayName</key>
<string>[ APP NAME ]</string>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>

我甚至更改了我的 NSAppTransportSecurity 设置。

I've even changed my NSAppTransportSecurity settings.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

我知道这是 iOS 9 Facebook登录模拟器-canOpenURL:网址失败:fbauth2:/// ; - 错误:(null)如何在iOS 10上使用Facebook iOS SDK 但是没有一个解决方案似乎适用于我,除非我错过了什么?

I know this is a duplicate of iOS 9 Facebook login simulator -canOpenURL: failed for URL: "fbauth2:///" - error: "(null)" and How to use Facebook iOS SDK on iOS 10 but none of the solutions there seem to work for me, unless I've missed something? Any suggestions are appreciated.

[App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction


[error] error: (6922) I/O error for database at /var/mobile/Containers/Data/Application/F3D8E126-B0CC-4C06-81A5-D7A7F849B3BD/Documents/OfflineModel2.sqlite.  SQLite error code:6922, 'disk I/O error'

当我没有FB应用程序安装在我的设备上,我得到:

And when I don't have the FB app installed on my device, I get:

-canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"


推荐答案

你必须用下面的代替dofinishlaunching和openurl AppDelegate方法:

You have to substitute didfinishlaunching and openurl AppDelegate methods with below:

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

public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool 
{
    return SDKApplicationDelegate.shared.application(app, open: url, options: options)
}

这篇关于Facebook SDK使用Swift 3 iOS 10登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆