UIWebView 本地加载网页和文件(图片素材,js,css)(功能插件化)

技术思想就是先将开发完成的html功能打包压缩(zip)放在服务器上,移动端使用某个功能时就下载对应的压缩文件,然后移动端解压使用对应的网页文件。为了体验效果比较好,所以将这些放在本地,至于原生和网页之间的交互,下面代码里面也有。

1.建议将UIWebView 所在的控制器封装重写

#pragma mark - UIWebViewDelegate


//开始加载

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

{

    NSString* scheme = [[requestURL]scheme];

    //判断是不是https

    if ([schemeisEqualToString:@"https"]) {

        //如果是https:的话,那么就用NSURLConnection来重发请求。从而在请求的过程当中吧要请求的URL做信任处理。

        if (!self.isAuthed) {

            NSURLConnection* conn = [[NSURLConnectionalloc]initWithRequest:requestdelegate:self];

            [conn start];

            [awebView stopLoading];

            returnNO;

        }

    }

    returnYES;

}


//设置webviewtitle为导航栏的title

- (void)webViewDidFinishLoad:(UIWebView *)webView

{

    self.title = [webViewstringByEvaluatingJavaScriptFromString:@"document.title"];

    CGRect frame = webView.frame;

    CGSize fittingSize = [webViewsizeThatFits:CGSizeZero];

    frame.size = fittingSize;

    webView.frame = frame;

    

    JSContext *context = [self.webViewvalueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

    /**

     *  弹出提示

     *

     *  @param alertTitle   <#alertTitle description#>

     *  @param alertMessage <#alertMessage description#>

     *

     *  @return <#return value description#>

     */

    context[@"PDAlert"] = ^(NSString * alertTitle,NSString * alertMessage){

        dispatch_async(dispatch_get_main_queue(), ^{

            //

            [selfPDAlertViewWithTitle:alertTitlemessage:alertMessagecancelButtonTitle:@"确定"otherButtonTitles:nil];

            

        

        });

        

    };

    

    

    context[@"PDGoBack"] = ^(){

        dispatch_async(dispatch_get_main_queue(), ^{

            //

            [selfbackNative];

        });

        

    };

    

    context[@"PDGetMap"] = ^(){

        dispatch_async(dispatch_get_main_queue(), ^{

            

        });

    };

}


#pragma mark ==========弹出提示框

-(void)PDAlertViewWithTitle:(NSString *)Title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSArray *)Titles{

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值