Javascript call ObjC

2,653
-1

Published on

A way of calling objc function from js in UIWebView.

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,653
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
32
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Javascript call ObjC

  1. 1. iOS dev HACK! JS ObjC linluxiang@gmail.com
  2. 2. HTML
  3. 3. HTMLJS Objc
  4. 4. HTMLJS ObjcUIWebView
  5. 5. JS Global
  6. 6. JS Global- (void)webView:(id)sender didClearWindowObject:(id)windowObject forFrame:(WebFrame*)frame {
  7. 7. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame {! [windowObject setValue:localcall forKey:@"localcall"];
  8. 8. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame {! [windowObject setValue:localcall forKey:@"localcall"];
  9. 9. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame {! [windowObject setValue:localcall forKey:@"localcall"];}
  10. 10. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame {! [windowObject setValue:localcall forKey:@"localcall"];} + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
  11. 11. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame {! [windowObject setValue:localcall forKey:@"localcall"];} + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector + (BOOL)isKeyExcludedFromWebScript:(const char *)name
  12. 12. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame {! [windowObject setValue:localcall forKey:@"localcall"];} + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector + (BOOL)isKeyExcludedFromWebScript:(const char *)name
  13. 13. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame {! [windowObject setValue:localcall forKey:@"localcall"];} + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector + (BOOL)isKeyExcludedFromWebScript:(const char *)name
  14. 14. Apple
  15. 15. Apple + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector aSelector
  16. 16. + (BOOL)isKeyExcludedFromWebScript:(const char *)name
  17. 17. + (BOOL)isKeyExcludedFromWebScript:(const char *)name
  18. 18. + (BOOL)isKeyExcludedFromWebScript:(const char *)name JS
  19. 19. RPC
  20. 20. RPC http://localcall/func_name?argument=”a_json_string”
  21. 21. RPC http://localcall/func_name?argument=”a_json_string”
  22. 22. Ajax
  23. 23. AjaxXMLHttpRequest
  24. 24. AjaxXMLHttpRequest
  25. 25. AjaxXMLHttpRequest Cache
  26. 26. Ajax XMLHttpRequest Cache- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request
  27. 27. Callback
  28. 28. Callbackwindow.location.href
  29. 29. Callbackwindow.location.href
  30. 30. Callback window.location.href- (BOOL)webView:(UIWebView *)webView2shouldStartLoadWithRequest:(NSURLRequest *)requestnavigationType:(UIWebViewNavigationType)navigationType
  31. 31. Callback window.location.href- (BOOL)webView:(UIWebView *)webView2shouldStartLoadWithRequest:(NSURLRequest *)requestnavigationType:(UIWebViewNavigationType)navigationType [webview loadData]
  32. 32. Callback window.location.href- (BOOL)webView:(UIWebView *)webView2shouldStartLoadWithRequest:(NSURLRequest *)requestnavigationType:(UIWebViewNavigationType)navigationType [webview loadData]- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script;
  33. 33. FormIframeScript webview cache
  34. 34. Read The F**king SourceCode.https://github.com/linluxiang/JavascriptCallObjCExample

×