Javascript中的UIWebView回调到C / Objective-C [英] Javascript in UIWebView callback to C/Objective-C

查看:117
本文介绍了Javascript中的UIWebView回调到C / Objective-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在UIWebView中检测到某个事件时,是否有一种方法来获取对objective-c的回调?可以JavaScript发送一个回调给Objective-C?

Is there a way to get a callback to objective-c when a certain event has been detected in a UIWebView? Can Javascript send a callback to Objective-C?

推荐答案

更新 - 不要使用UIWebView了。使用WKWebView或更好的(如果它适合你的需要,你正在为iOS 9构建),一个Safari视图控制器。

Update - don't use UIWebView anymore. Use WKWebView, or better yet (if it fits your needs and you're building for iOS 9), a Safari View Controller.

但是如果你必须使用UIWebView,您的UIWebView委托,提供 webView:shouldStartLoadWithRequest:navigationType:

But if you must use UIWebView, in your UIWebView delegate, provide an implementation for webView:shouldStartLoadWithRequest:navigationType:

在HTML或Javascript文件中,将URL发送到自定义方案(出于可读性目的,不需要自定义方案)。所有发送的URL都将传递给你的Objective-C方法实现,然后你可以做你想要的。

In your HTML or Javascript files, add functions that send URLs to a custom scheme (for readability purposes, the custom scheme isn't required). All the URLs sent will be passed to your Objective-C method implementation, and then you can do what you'd like.

这篇关于Javascript中的UIWebView回调到C / Objective-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆