zoukankan      html  css  js  c++  java
  • 第三方登陆UIWebView渲染数据的问题

            做第三方登陆,使用UIWebView加载服务端封装的一个连接,然后服务端返回QQ或新浪微博的登陆页,输入用户名和密码后,服务端处理所有的先关账号的关联操作后,把登陆成功后的用户名信息渲染到到UIWebView上。此时就会存在一个用户会看到UIWebView上的数据,所以需要别的方式处理这个方式。

            判断当要访问返回登陆信息的URL地址的时候,阻止加载这个地址,使用创建两外一个UIWebView加载这个地址。

            方法如下:

    #pragma mark - UIWebViewDelegate Method


    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

        NSString *currentURL = request.URL.absoluteString;

        // 判断是否要加载返回的登陆信息的URL地址

        if ([currentURL rangeOfString:@"/appsina?"].location != NSNotFound || [currentURL rangeOfString:@"/appqq?"].location != NSNotFound) {

            if (webView.tag == kGetLoginInfo) {

                return YES;

            }

            [_tempWebView release];

            _tempWebView = [[UIWebView alloc] init];    // 创建新的UIWebView加载最终的URL地址

            NSURL *url = [NSURL URLWithString:currentURL];        

            NSMutableURLRequest* request = [NSMutableURLRequestrequestWithURL:url];

            request.HTTPMethod = @"GET";

            [_tempWebView loadRequest:request];

            _tempWebView.delegate = self;

            _tempWebView.tag = kGetLoginInfo;

            return NO;

        }

        returnYES;

    }

    - (void)webViewDidFinishLoad:(UIWebView *)webView {

        [self.indicatorViewstopAnimating];

        NSString * currentURL = [webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];    // 获取网页内容

        if ([currentURL rangeOfString:@"/appsina?"].location != NSNotFound || [currentURL rangeOfString:@"/appqq?"].location != NSNotFound) {

            [self loginSuccessed:webView];

        }

    }


  • 相关阅读:
    C# NewtonJson Serialize and deserialize
    C# bubble sort,selection sort,insertion sort
    C# 7
    C# aggregateexception flatten innerexceptions
    C# monitor keyboard and mouse actions based on MouseKeyHook.
    C# monitor keyboard and print pressed key
    svn命令行
    正则表达式
    对象的浅拷贝跟深拷贝
    conso.log占位符
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3049868.html
Copyright © 2011-2022 走看看