在我的应用程序中,我使用网络身份验证登录我的应用程序,如下图所示:
现在我遇到了一个问题,有时我登录然后注销并再次登录,uiwebview显示一个空白的白页如下:
我不知道发生了什么。有人得到这样的问题吗?我该如何解决?
这是代码:
- (void)loadWebView {
NSString *urlString = @"https://api.ewings.vn/dialog/SdkWebView/login/?";
urlString = [urlString stringByAppendingString:[NSString stringWithFormat:@"redirect_uri=sh%@://",[Soha sharedInstance].gameId]];
NSDictionary *defaultParam = [SHRequest addMoreParametersForSOAPAPIsFromParam:nil WithOldAPI:NO];
for (NSString *key in defaultParam.allKeys) {
urlString = [urlString stringByAppendingString:[NSString stringWithFormat:@"&%@=%@", key, [defaultParam objectForKey:key]]];
}
[self.loginWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if([request.description containsString:@"access_token"]){
NSString* accessToken = [request.description componentsSeparatedByString:@"access_token="][1];
accessToken = [accessToken componentsSeparatedByString:@"&"][0];
NSString *decoded = (__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (CFStringRef)accessToken, CFSTR(""), kCFStringEncodingUTF8);
[Soha sharedInstance].gameAccessToken = decoded;
[[SHLoginModal sharedModal] getUserInfoWithBlock:^(NSDictionary *userInfo, NSError *error) {
if (accessToken) {
[self loginSuccessfully];
self.loginWebview = nil;
}
}];
}
NSLog(@"request des : %@",[request URL]);
return YES;
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
self.backButton.enabled = (self.loginWebview.canGoBack);
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
self.backButton.enabled = (self.loginWebview.canGoBack);
}
- (void)viewDidLoad {
[super viewDidLoad];
self.loginWebview.delegate = self;
self.navigationView.backgroundColor = SHColorFromHEX(0x167AC6);
[self.navigationTitle setText:@"Login"];
[self.backButton addTarget:self.loginWebview
action:@selector(goBack)
forControlEvents:UIControlEventTouchDown];
[self loadWebView];
}