web端vue.js 交互iOS

form:http://mengyujing.com/vue%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8WebViewJavascriptBridge/

方法一:用 funcTest(xxx://aaa&bbb&ccc)
这种方法最简单,多个参数之间约定间隔字符串就好了,iOS端监听 xxx 协议即可
这里需要使用到:

#pragma mark - UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
 navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL * url = [request URL];
    if ([[url scheme] isEqualToString:@"firstclick"])
    {
        NSArray *params =[url.query componentsSeparatedByString:@"&"];

        NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
        for (NSString *paramStr in params)
        {
            NSArray *dicArray = [paramStr componentsSeparatedByString:@"="];
            if (dicArray.count > 1)
            {
                NSString *decodeValue = [dicArray[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                [tempDic setObject:decodeValue forKey:dicArray[0]];
            }
        }

        NSString *cntent = [NSString stringWithFormat:@"%@", tempDic];

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"JS调用OC-OC原生弹框" message:cntent delegate:self cancelButtonTitle:@"收到" otherButtonTitles:nil];
        [alertView show];

        NSLog(@"tempDic:%@",tempDic);
        return NO;
    }

    return YES;
}

方法二:web端需要使用第三方库,具体见最上方连接。

猜你喜欢

转载自blog.csdn.net/wokenshin/article/details/82350716