And*_*lli 3 facebook-graph-api ios swift
我正在使用Facebook SDK实现OAuth登录,但是FBSession.openActiveSessionWithReadPermissions:allowLoginUI:completionHandler方法没有调用completionHandler,也没有返回"true",这表示缓存的令牌.除此之外,其他一切似乎都很好.这段代码出了什么问题?
var completionHandler: FBSessionStateHandler = {
session, status, error in
NSLog("token not cached");
if error {
// Login failed for some reason, so we notify the delegate.
self.delegate.didFailOpenningSession?(self, withError: ErrorUtility.error(
code: .FailedOpenningSession,
withFacebookError: error
));
// Don't proceed on errors
return;
}
// Session is now open, we should notify the delegate
self.delegate.didOpenSession?(self);
};
NSLog("here");
// Open the session, prompting the user if necessary. This might send the application to the background
if FBSession.openActiveSessionWithReadPermissions(["public_profile"], allowLoginUI: true, completionHandler: completionHandler) {
NSLog("Token cached");
// If we end up here, the session token must exist, so we now have an open session
self.delegate.didOpenSession?(self);
}
Run Code Online (Sandbox Code Playgroud)
编辑:我忘了提到NSLog记录"here",但不是"Token cached",也不是"token not cached"
编辑:现在事情有点奇怪了.当我的应用程序启动时,我会显示一个带有Facebook登录按钮的屏幕.当用户按下按钮时,上面的代码被触发.在我授权应用程序之后,应用程序返回到同一个屏幕(它不应该,但是在调用完成处理程序之前我不能以任何其他方式执行).然后我再次尝试按下按钮,现在我确实得到了日志.
这就是我得到的:
here
token not cached
here
Run Code Online (Sandbox Code Playgroud)
第一行是从第一次按下按钮,另外两行是在我第二次按下时出现的.现在有什么奇怪的呢?不应该"令牌没有缓存"和"这里"被逆转??? 它是从最后一次通话中调用competionHandler还是其他什么东西?
没关系,这很多都是固定的.
编辑:另一件事.如果我多次按下按钮,我总是得到"令牌未缓存".我认为它应该是缓存
| 归档时间: |
|
| 查看次数: |
4073 次 |
| 最近记录: |