How can I open the Objective-C function for JavaScript using WebKit on Mac OS X?

I understand that for this on iPhone you need to catch communication requests (according to my other iPhone UIWebView Expose JavaScript question ), and you can easily do the opposite and access JavaScript from Obj-C code.

However, I would like JavaScript to call some Objective-C functions that will somehow be registered with WebKit. I assume that you can do this better than link grabbing, like on an iPhone, since on Mac OS X we have access to the full WebKit.

I want to basically do the opposite Using JavaScript from Objective-C

Update: For example, you can expose the Objective-C method in JavaScript, for example self.external.objcmethod ();

+3
source share
3 answers

Check out my answer to this question , which is very similar. I provide code that accurately shows how to do what you want.

Essentially, you need to implement the WebScripting protocol in accordance with the documentation .

URL, iPhone. Mac WebView , UIWebView iPhone, JavaScript Objective-C .

+6

"javascript: my_method()" ...

UIWebViewDelegate.

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/Reference/Reference.html

shouldStartLoadWithRequest
((BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType)

, https://dev.mobileread.com/trac/webkitbrowser/browser/trunk/WebKit-r30377/WebKit/qt/Api/qwebframe.cpp#L167

0

, , - URL. HTML , myapp://dosomefunction?aParameter=aValue. Mac OS X ( ) URL- . , , - .

. , . , . .

0

Source: https://habr.com/ru/post/1744894/


All Articles