我正在尝试创建一个facebook登录身份验证,但是我一直遇到问题,当用户点击按钮时它打开浏览器并且我登录,但是当我登录并给予许可时没有任何反应并且它没有关闭浏览器并返回应用程序。另一件事是当我再次打开应用程序并检查令牌它返回nil,即使它应该已经登录?
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if ((error) != nil)
{
// Process error
}
else if result.isCancelled {
// Handle cancellations
}
else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if result.grantedPermissions.contains("email") && result.grantedPermissions.contains("public_profile") && result.grantedPermissions.contains("user_friends")
{
}
}
}
viewDidLoad中
//Check for access
if (FBSDKAccessToken.current() != nil) {
print("Logged in")
} else {
self.performSegue(withIdentifier: "GoToIntro", sender: self)
}
的appDelegate
private func application(application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
的plist
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb1645871657973243</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>1645871657973243</string>
<key>FacebookDisplayName</key>
<string>testy</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
答案 0 :(得分:1)
我几天前用iOS 10和Swift 3实现了FBSDK并且它不是很流畅。对我来说最大的问题可能是你发生了什么 - 新的SDK想要在iPhone上打开Facebook应用程序,但模拟器自然没有它。检查这一点很简单 - 出现以下错误:
-canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
我有这个问题已经有好几天了,直到我环顾四周并找到Apple开发论坛。另一个可能的原因是您没有正确实现AppDelegate功能。不推荐使用旧的FBSDKApplicationDelegate.sharedInstance()。application(...)函数。经过一番搜索后,我想出了以下实现,这对我有用:
func application(_ app: UIApplication, open url: URL, options: [String : AnyObject] = [:]) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String,
annotation: nil)
return true
}
答案 1 :(得分:0)
在ViewDidLoad
方法中,你必须放置:
yourLoginFacebookButton.delegate = self
在您的Login类中,您必须执行此实现:
FBSDKLoginButtonDelegate