我在OAuthStarterKit
中运行并正常工作(Web视图很慢!)基本视图附带了一些用于检测弹出webview何时关闭的基本代码(请参阅以下函数)。
问题是,当用户出现Linkedin登录页面时,它无法检测到用户点击取消按钮的时间。网址:https://www.linkedin.com/uas/oauth/www.core.me
。
如何过滤“已取消”页面?
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
addressBar.text = urlString;
[activityIndicator startAnimating];
BOOL requestForCallbackURL = ([urlString rangeOfString:linkedInCallbackURL].location != NSNotFound);
if ( requestForCallbackURL )
{
BOOL userAllowedAccess = ([urlString rangeOfString:@"user_refused"].location == NSNotFound);
if ( userAllowedAccess )
{
[self.requestToken setVerifierWithUrl:url];
[self accessTokenFromProvider];
}
else
{
// User refused to allow our app access
// Notify parent and close this view
[[NSNotificationCenter defaultCenter]
postNotificationName:@"loginViewDidFinish"
object:self
userInfo:nil];
[self dismissModalViewControllerAnimated:YES];
}
}
else
{
// Case (a) or (b), so ignore it
}
return YES;
}
答案 0 :(得分:0)
这是我最终在我的代码中使用的内容!希望它可以帮助别人!
- (void)webViewDidFinishLoad:(UIWebView *)mwebView
{
[activityIndicator stopAnimating];
NSString *html = [mwebView stringByEvaluatingJavaScriptFromString:
@"document.body.innerHTML"];
if ([html rangeOfString:@"Page Not Found"].location != NSNotFound) {
// This could be any string - I used "Page Not Found"
[[NSNotificationCenter defaultCenter]
postNotificationName:@"loginViewDidFinish"
object:self
userInfo:nil];
[self dismissModalViewControllerAnimated:YES];
}
}