[英]Facebook SDK 4.0 - currentAccessToken still nil within loginButton didCompleteWithResult
I am upgrading to Facebook SDK 4.X and I am having trouble determining what to do immediately after login. 我正在升级到Facebook SDK 4.X,无法确定登录后立即执行的操作。
In the Facebook Delegate's loginButton didCompleteWithResult
method, it returns successfully (skips the error
if statement), so for my system I need to register the user with my server, so in the previous version of the Facebook SDK, I would send the access token to my server. 在Facebook代表的
loginButton didCompleteWithResult
方法中,它成功返回(跳过if语句error
),因此对于我的系统,我需要在服务器上注册用户,因此在Facebook SDK的早期版本中,我会将访问令牌发送到我的服务器。
But in this didCompleteWithResult
method, [FBSDKAccessToken currentAccessToken]
is still returning nil
但是在此
didCompleteWithResult
方法中, [FBSDKAccessToken currentAccessToken]
仍返回nil
all my AppDelegate lifecycle methods return the facebook functions, so I'm not sure what else could be happening incorrectly, or where I should expect the AccessToken to be populated 我所有的AppDelegate生命周期方法都返回了facebook函数,所以我不确定其他可能会发生的错误,或者我应该在哪里填充AccessToken
You probably forgot the call the FBSDKApplicationDelegate
in the didFinishLaunchingWithOptions
method. 您可能忘记了
didFinishLaunchingWithOptions
方法中的FBSDKApplicationDelegate
调用。
See the answer here: https://stackoverflow.com/a/30406194/561485 . 在此处查看答案: https : //stackoverflow.com/a/30406194/561485 。
The documentation explains more about the application:didFinishLaunchingWithOptions: method. 该文档解释了有关application:didFinishLaunchingWithOptions:方法的更多信息。
In my case I was facing this issue as I was using another Google sign in as well. 就我而言,当我也使用另一个Google登录时,我遇到了这个问题。 So, the url wasn't handled by facebook sdk.
因此,该URL不是由facebook sdk处理的。 I had to change the app delegate methods as follows:
我必须更改应用程序委托方法,如下所示:
@available(iOS 9.0, *)
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any])
-> Bool {
let gHandle = GIDSignIn.sharedInstance().handle(url,
sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: [:])
let fHandle = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, options: options)
return gHandle || fHandle
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.