您的位置:首页 > 移动开发 > IOS开发

推特登录出错后没有拿到错误返回

2016-12-06 14:51 453 查看
参考:http://blog.csdn.net/pz789as/article/details/53486568

前不久将推特的授权登录加入到自己的项目中来,今天测试时发现,在没有翻墙时,点击推特登录之后一直没有反应,然后看log发现,推特本身是给出了提示:

did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "" UserInfo={NSLocalizedDescription=}
 
但是我这边也都对error做了处理和打印,却并没有接收到错误信息,导致应用一直停在waiting状态,无法操作!

调用推特登录代码如下:

[[Twitter sharedInstance] logInWithMethods:TWTRLoginMethodWebBased completion:^(TWTRSession* session, NSError* error) {
if (session){
NSLog(@"signed in as %@", [session userName]);
[self twlCallback:CB_CODE_LOGIN result:
[NSString stringWithFormat:@"{\"userName\": \"%@\",\"userID\": \"%@\",\"authToken\": \"%@\",\"authTokenSecret\": \"%@\"}",
[session userName],
[session userID],
[session authToken],
[session authTokenSecret]
]
];
}else{
NSLog(@"error: %@", [error localizedDescription]);
[self twlCallback:CB_CODE_ERROR
result:[NSString stringWithFormat:@"{\"id\":\"%@\", \"dsc\":\"%@\"}",
ERROR_LOGIN,
[error localizedDescription]]];
}
}];


后面log在判断session外面发现,根本没有回调这个函数。

于是在网上找答案,然后在推特的论坛上找到这么一个答案:
https://twittercommunity.com/t/problem-using-twitterkit-to-login-via-oauth/73379
Thanks for reaching out on this. Have you made any customizations to the 
TWTRLoginMethod
 enum
defined in Twitter.h along with the 
[Twitter
logInWithMethods:completion:]
 method? By default, Twitter Kit will choose log in methods in the following order 
[System
Account]
 -> 
[SFSafariViewController]
 -> 
[UIWebView]
.
With the 
TWTRLoginMethod
 enum,
the developer can choose which methods to use when providing the user with the ability to log in using Twitter.

个人觉得应该是登录的方式不对,于是乎,将上面的代码中的

TWTRLoginMethodWebBased
改成

TWTRLoginMethodAll
就可以拿到结果啦,它会提示timeout,这样就可以做下一步操作了!心情瞬间舒畅了很多啊

改了之后的提示是这样的:

did encounter error with message "Unable to authenticate using the system account.": Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."
然后就可以弹出提示框了:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐