![](/img/trans.png)
[英]Facebook Login iOS 10 works until button is pressed for a second time
[英]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)
}
})
}
}
为什么会发生这种情况,如何解决?
我意识到问题出在应用程序委托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.