UIWebView Expose Objective C to JavaScript
Solution 1
The best way to do this would be through a custom link, and then use the UIWebView delegate method -webView:shouldStartLoadWithRequest:navigationType:
to trap requests. When you see a request come through with your link in it, you know your action has been triggered.
Solution 2
There is an example application in the QuickConnectiPhone framework that shows you how to do this.
QuickConnectiPhone also gives you a JavaScript function called 'makeCall'. You pass it a command and an array of parameters and it will pass them to the Objective-C side of your app for handling. You can then make your function call.
You can find it here on Sourceforge.
Luke
Favorite Languages: .NET (VB.NET and C#), WPF (XAML), PHP, XHTML, CSS and JavaScript (jQuery) Least Favorite Languages: Objective-C, Java Interests: Programming, User Interface Design, Microsoft, Google and Apple
Updated on June 26, 2022Comments
-
Luke about 2 years
How would I expose an Objective-C method within JavaScript when using the iPhone SDK when using the
UIWebView
?Any help would be appreciated!