Framework文件

  • FireflyWebPluginService.framework

配置链接

  • 需要添加FireflyWebPluginService.framework的链接,以及对应的依赖链接

头文件引用

简单导入

#import <FireflyWebPluginService/FireflyWebPluginService.h>

原理

注册NSURLProtocol的子类,以拦截UIWebView的网络请求,对符合规则的请求进行重定向,将网络IO定向到本地IO。

受限于苹果应用商店政策原因,离线包不支持WKWebView。

使用步骤

1、注册FireflySessionURLProtocol,建议在加载WebView之前前注册

[NSURLProtocol registerClass:[FireflySessionURLProtocol class]];

2、注册本地化过滤器

[FireflySessionURLProtocol filter_register:[FireflySessionURLCustomFilter class]];

3、覆写FireflySessionURLCustomFilter的方法

//FireflySessionURLCustomFilter子类

+(BOOL)ff_canDoWithRequest:(NSURLRequest *_Nonnull)inRequest canonicalRequest:(NSURLRequest *_Nonnull*_Nullable)outRequest outUserData:(NSObject *_Nullable*_Nonnull)outUserData
{
    //下面代码示意过滤判断
    if (!inRequest  || !inRequest.URL)
        return NO;

    NSString *scheme = [inRequest.URL.scheme lowercaseString];
    if (![scheme isEqualToString:@"http"] && ![scheme isEqualToString:@"https"])
        return NO;

    NSString *userAgent = [inRequest valueForHTTPHeaderField:@"User-Agent"];
    if ([userAgent rangeOfString:@"AppleWebKit"].location == NSNotFound)
        return NO;

    //只有结果为YES时,才会有(但不一定有)后续的处理过程
    return YES;
}

-(NSString *_Nonnull)localFilePath
{
    return @"本地文件";
}
Copyright © 民生科技有限公司 2019 all right reserved,powered by Gitbook联系方式: wanglihang@mskj.com
修订时间: 2019-08-02 16:19:33

results matching ""

    No results matching ""