簡體   English   中英

Facebook登錄Swift iOS 10-無效

[英]Facebook Login Swift iOS 10 - Nothing Works

我正在運行最新版本的XCode和Swift。 我正在嘗試實施Facebook登錄; 但是,我一直遇到持續的錯誤。

首先我得到這個:

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

我實施了此處列出的解決方案, 但仍然沒有運氣 如何在iOS 10上使用Facebook iOS SDK

我試過仔細檢查“鑰匙串訪問”,重新安裝FacebookSDK,並以各種不同的方式實現它,例如: http : //ashishkakkad.com/2015/05/facebook-login-swift-language-ios,但我似乎無法避開這個。

這是我的登錄結果: Optional(<FBSDKLoginManagerLoginResult: 0x170251550>

不確定是否正確。 雖然我沒有網絡中斷並且我的wifi已完全連接,但我也收到此錯誤。 Could not successfully update network info during initialization.

    @IBAction func fbLoginButtonPressed(_ sender: AnyObject) {
        let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
        fbLoginManager.logIn(withReadPermissions: ["email"], from: self) { (result, error) in
            print("Here is the result", result)
            print("Here is the error" , error)

            if (error == nil){
                print("the error is nil")
                let fbloginresult : FBSDKLoginManagerLoginResult = result!
                //commenting if statement out temporarily for debugging purposes

//                if(fbloginresult.grantedPermissions.contains("email"))
//                {
                print("email is contained and printing result")
                self.getFBUserData()
                fbLoginManager.logOut()
//                }
            }
        }
    }

    func getFBUserData(){
        if((FBSDKAccessToken.current()) != nil){
            FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start(completionHandler: { (connection, result, error) -> Void in

                print("inside get FB user data")
                if (error == nil){
                    self.dict = result as! [String : AnyObject]
                    print(result!)
                    print(self.dict)
                }
            })
        }
    }

為什么會發生這種情況,如何解決?

您的代碼很完美,但是您必須啟用Facebook登錄的鑰匙串訪問權限

那會解決你的問題

圖片

我意識到問題出在應用程序委托https://gist.github.com/codegefluester/f797dd723e93e545b855525a4b9ab057

import UIKit
import CoreData

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
        // Override point for customization after application launch.

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

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

        return FBSDKApplicationDelegate.sharedInstance().application(
            app,
            open: url as URL!,
            sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
            annotation: options[UIApplicationOpenURLOptionsKey.annotation]
        )
    }

    public 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)
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM