WebView

// 初始化
self.urlString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)self.urlString,NULL,NULL,kCFStringEncodingUTF8));

    _webView.scalesPageToFit = YES;
    _webView.multipleTouchEnabled = YES;
    _webView.userInteractionEnabled = YES;
    _webView.scrollView.scrollEnabled = YES;

    NSURL *url=[NSURL URLWithString:self.urlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];


// 代理方法
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    NSString *requestURL = [[request URL] absoluteString];

    if ([requestURL rangeOfString:@"native://back"].length > 0) {
        [self.navigationController popToRootViewControllerAnimated:YES];
        return NO;
    }

    if([requestURL rangeOfString:@"native://BookRoom"].length > 0 || [requestURL rangeOfString:@"native://ScanQRCode/Schedule"].length > 0)
    {
        return NO;
    }
    return YES;
}


// 清除缓存
- (void)cleanCacheAndCookie{

    NSHTTPCookie *cookie;
    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

    for(cookie in [storage cookies]){
        [storage deleteCookie:cookie];
    }

    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    NSURLCache * cache = [NSURLCache sharedURLCache];
    [cache removeAllCachedResponses];

    [cache setDiskCapacity:0];
    [cache setMemoryCapacity:0];
}

// 放大缩小
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [self hideWaiting];

    NSString *jsMeta = [NSString stringWithFormat:@"var meta = document.createElement('meta');meta.content='width=device-width,initial-scale=1.0,minimum-scale=.5,maximum-scale=3';meta.name='viewport';document.getElementsByTagName('head')[0].appendChild(meta);"];
    [_webView stringByEvaluatingJavaScriptFromString:jsMeta];
}

results matching ""

    No results matching ""