zoukankan      html  css  js  c++  java
  • objc>JS通信及JS>objc通信

    一、obj-c--->JS通信

    NSString *path = [[NSBundlemainBundle]

                              pathForResource:@"xxxx"

                              ofType:@"html"

                              inDirectory:@"xxx"];

            NSURL *url = [NSURL fileURLWithPath:path];

            NSString *theAbsoluteURLString = [url absoluteString];

            NSString *queryString = @"需要传进html中的参数";

        

            NSString *absoluteURLwithQueryString = [theAbsoluteURLString stringByAppendingString: queryString];

            NSURL *finalURL = [NSURL URLWithString: absoluteURLwithQueryString];

            NSURLRequest *request = [NSURLRequestrequestWithURL:finalURL cachePolicy:NSURLRequestReloadIgnoringCacheDatatimeoutInterval:(NSTimeInterval)10.0 ];

            [webView loadRequest:request];

    二、JS--->obj-c通信

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

    {

        NSLog(@"-----%@", request.mainDocumentURL.relativePath);

        if ([request.mainDocumentURL.relativePath.lastPathComponentisEqualToString:@"xxx.html"])

        {

        return NO;

        }

          returnYES;

    }

  • 相关阅读:
    安卓移动端css3动画卡顿解决方法
    PDO方法实现增删改查
    NPOI 操作笔记
    基于emoji 国际通用表情在web上的输入与显示的记录
    restful 规范
    set与map
    ES6解构赋值
    scss的基本用法
    学习vue的第一二三四五天
    React Hooks --- useState 和 useEffect
  • 原文地址:https://www.cnblogs.com/ouyangfang/p/2870070.html
Copyright © 2011-2022 走看看