2019-08-25WKWebView踩坑1.0

2019-08-25  本文已影响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;
}
上一篇下一篇

猜你喜欢

热点阅读