美文网首页
H5与ios原生交互

H5与ios原生交互

作者: 奋斗的蜗牛 | 来源:发表于2016-06-21 15:31 被阅读290次

你得h5界面的按钮点击实现方法

window.location.href = "协议名:其他啥啥"; 
window.location.href = "ios:back";

然后你在你的webview代理方法

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
 NSString *requestString = [[request URL] absoluteString];
  requestString = [requestString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    if( navigationType == UIWebViewNavigationTypeOther ) {
        if ([requestString hasPrefix:@"ios:"]) {
           //开始处理你的逻辑,你想跳转怎么跳转 你自己控制呗
          //比如我处理跳出webview
         [self.navigationController popViewControllerAnimated:YES];
            return NO;
        }
    }
    return YES;
}

相关文章

网友评论

      本文标题:H5与ios原生交互

      本文链接:https://www.haomeiwen.com/subject/gcphdttx.html