Javascript in UIWebView callback to C/Objective-C

后端 未结 2 1259
既然无缘
既然无缘 2020-11-27 03:44

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?

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 03:57

    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.

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

    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.

提交回复
热议问题