美文网首页
2019-08-25WKWebView踩坑1.0

2019-08-25WKWebView踩坑1.0

作者: 破夕_____________ | 来源:发表于2019-08-25 15:15 被阅读0次

    实现JS读取iOS本地写入的LocalStorage

    判断清除缓存

    if (@available(iOS 9.0, *))
        {//清除缓存
            NSSet * websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
            NSDate * dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
            [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
                JMLog(@"--%@\n--%@",websiteDataTypes,dateFrom);
            }];
        }
    

    配置webView 设置 WKProcessPool允许本地存储 设置单例

    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
        
        configuration.processPool = [User shareInstanceWKProcessPool];
    
        [configuration.userContentController addScriptMessageHandler:self name:@"pipeline"];//设置用户交互
    

    单例

    + (WKProcessPool *)shareInstanceWKProcessPool
    {
        static WKProcessPool *sharedPool = nil;
        
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            sharedPool = [[WKProcessPool alloc] init];
        });
        return sharedPool;
    }
    

    相关文章

      网友评论

          本文标题:2019-08-25WKWebView踩坑1.0

          本文链接:https://www.haomeiwen.com/subject/bynhectx.html