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;

    }

  • 相关阅读:
    JDk和Mevan安装和配置
    如何修改windows系统的host文件
    字符串格式化
    可变和不可变的数据类型
    拦截
    eclipse格式化代码模板
    oracle语法练习汇总
    PLSQL语法
    oracle创建完实例删除的时候报ORA-01031:insufficient privileges错误,解决办法
    socket多线程方式案例
  • 原文地址:https://www.cnblogs.com/ouyangfang/p/2870070.html
Copyright © 2011-2022 走看看