简体   繁体   English

Facebook登录Swift iOS 10-无效

[英]Facebook Login Swift iOS 10 - Nothing Works

I'm running the most recent version of XCode and Swift. 我正在运行最新版本的XCode和Swift。 I'm trying to implement Facebook Login; 我正在尝试实施Facebook登录; however, I keep on running into persistent errors. 但是,我一直遇到持续的错误。

First I am getting this: 首先我得到这个:

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

I implemented the solutions listed here yet still no luck . 我实施了此处列出的解决方案, 但仍然没有运气 How to use Facebook iOS SDK on iOS 10 如何在iOS 10上使用Facebook iOS SDK

I've tried double checking Keychain Access On, Reinstalling FacebookSDK, implementing it in various different ways such as: http://ashishkakkad.com/2015/05/facebook-login-swift-language-ios but I can't seem to get around this. 我试过仔细检查“钥匙串访问”,重新安装FacebookSDK,并以各种不同的方式实现它,例如: http : //ashishkakkad.com/2015/05/facebook-login-swift-language-ios,但我似乎无法避开这个。

Here is my login result: Optional(<FBSDKLoginManagerLoginResult: 0x170251550> 这是我的登录结果: Optional(<FBSDKLoginManagerLoginResult: 0x170251550>

Not sure if that is right. 不确定是否正确。 Also I get this error though I don't have network loss on and my wifi is perfectly connected. 虽然我没有网络中断并且我的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)
                }
            })
        }
    }

Why is this occurring and how can this be resolved? 为什么会发生这种情况,如何解决?

Your Code is perfect but you have to Enable Keychain access for Facebook Login in 您的代码很完美,但是您必须启用Facebook登录的钥匙串访问权限

That will solve your problem 那会解决你的问题

图片

I realized the problem was in the App Delegate https://gist.github.com/codegefluester/f797dd723e93e545b855525a4b9ab057 我意识到问题出在应用程序委托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