Javascript in UIWebView callback to C/Objective-C

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.

Leave a Comment