Facebook登录Swift iOS 10 - 无效 [英] Facebook Login Swift iOS 10 - Nothing Works

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

问题描述

我正在运行XCode和Swift的最新版本。我正在试图实现Facebook登录;但是,我继续遇到持续的错误。



首先我得到这个:

  -canOpenURL:failed for URL:fbauth2:/ - 错误:操作无法完成(OSStatus错误-10814)

我实施了这里列出的解决方案,但仍然没有运气。
如何在iOS 10上使用Facebook iOS SDK



我已经尝试过双重检查钥匙串访问,重新安装FacebookSDK,以各种不同的方式实现它,例如: http://ashishkakkad.com/2015/05/facebook-login-swift-language-ios 我似乎无法解决这个问题。



这是我的登录结果:可选(&FBSDKLoginManagerLoginResult:0x170251550>



不知道是否是正确的,我也收到这个错误,虽然我没有网络损失,我的wifi是完美的连接。在初始化期间无法成功更新网络信息。

  @IBAction func fbLoginButtonPressed(_ sender:AnyObject){
let fbLoginManager:FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logIn(withReadPermissions:[email],from:self){(result,error)in
print(这是结果,结果)
print(这是错误,错误)

if(error == nil){
print(the error is nil)
let fbloginresult:FBSDKLoginManagerLoginResult = result !
//注释if语句暂时用于调试目的

// if(fbloginre sult.grantedPermissions.contains(email))
// {
打印(包含电子邮件和打印结果)
self.getFBUserData()
fbLoginManager.logOut( )
//}
}
}
}

func getFBUserData(){
if((FBSDKAccessToken.current())! = nil){
FBSDKGraphRequest(graphPath:me,参数:[fields:id,name,first_name,last_name,picture.type(large),email])start(completionHandler:{连接,结果,错误) - >

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

为什么会发生这种情况,如何解决?

解决方案

我意识到应用程序代理中的问题是 https:// gist。 github.com/codegefluester/f797dd723e93e545b855525a4b9ab057

  import UIKit 
import CoreData

@UIApplicationMain
class AppDelegate:UIResponder,UIApplicationDelegate {

var window:UIWindow?


public func应用程序(_应用程序:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey:Any]?= nil) - > Bool {
//在应用程序启动后重写自定义点。

返回FBSDKApplicationDelegate.sharedInstance()。应用程序(应用程序,didFinishLaunchingWithOptions:launchOptions)
}

public func应用程序(_ app:UIApplication,打开url:选项:[UIApplicationOpenURLOptionsKey:Any] = [:]) - > Bool {

return FBSDKApplicationDelegate.sharedInstance()。application(
app,
open:url as URL !,
sourceApplication:options [UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
注释:选项[UIApplicationOpenURLOptionsKey.annotation]

}

public func应用程序(_应用程序:UIApplication,打开url:URL,sourceApplication:String? ,注释:Any) - > Bool {
return FBSDKApplicationDelegate.sharedInstance()。application(
application,
open:url as URL !,
sourceApplication:sourceApplication,
annotation:annotation)
}
}


I'm running the most recent version of XCode and Swift. I'm trying to implement Facebook Login; 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

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.

Here is my login result: 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. 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?

解决方案

I realized the problem was in the App Delegate 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)
    }
}

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

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