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;

    }

  • 相关阅读:
    数据库的视图概念作用
    常见的反爬虫和应对方法
    referrer policy
    JSON
    异步消息处理机制
    Acitivity(活动)
    springboot @Autowired 空指针异常问题处理
    CentOS7 宝塔 ThinkPHP SQLServer 2000 安装FreeTDS
    PHP THINKPHP 函数 dump var_dump var_export
    ThinkPHP5 WHERE AND OR 实现多条件查询
  • 原文地址:https://www.cnblogs.com/ouyangfang/p/2870070.html
Copyright © 2011-2022 走看看