SlideShare a Scribd company logo
iOS dev HACK!
     JS    ObjC
 linluxiang@gmail.com
Javascript call ObjC
HTML
HTML

JS     Objc
HTML

JS     Objc

UIWebView
Javascript call ObjC
JS Global
JS Global

- (void)webView:(id)sender didClearWindowObject:(id)
windowObject forFrame:(WebFrame*)frame {
JS Global

  - (void)webView:(id)sender didClearWindowObject:(id)
  windowObject forFrame:(WebFrame*)frame {

! [windowObject setValue:localcall forKey:@"localcall"];
JS Global

  - (void)webView:(id)sender didClearWindowObject:(id)
  windowObject forFrame:(WebFrame*)frame {

! [windowObject setValue:localcall forKey:@"localcall"];
JS Global

    - (void)webView:(id)sender didClearWindowObject:(id)
    windowObject forFrame:(WebFrame*)frame {

! [windowObject setValue:localcall forKey:@"localcall"];

}
JS Global

    - (void)webView:(id)sender didClearWindowObject:(id)
    windowObject forFrame:(WebFrame*)frame {

! [windowObject setValue:localcall forKey:@"localcall"];

}

    + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
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
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
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
Javascript call ObjC
Apple
Apple

  + (BOOL)isSelectorExcludedFromWebScript:
(SEL)aSelector   aSelector
Javascript call ObjC
Javascript call ObjC
Javascript call ObjC
Javascript call ObjC
Javascript call ObjC
+ (BOOL)isKeyExcludedFromWebScript:
(const char *)name
+ (BOOL)isKeyExcludedFromWebScript:
(const char *)name
+ (BOOL)isKeyExcludedFromWebScript:
(const char *)name




         JS
Javascript call ObjC
RPC
RPC

          http://localcall/func_name?
argument=”a_json_string”
RPC

          http://localcall/func_name?
argument=”a_json_string”
Ajax
Ajax

XMLHttpRequest
Ajax

XMLHttpRequest
Ajax

XMLHttpRequest




                 Cache
Ajax

     XMLHttpRequest




                                         Cache

- (NSCachedURLResponse *)cachedResponseForRequest:
(NSURLRequest *)request
Callback
Callback
window.location.href
Callback
window.location.href
Callback
          window.location.href



- (BOOL)webView:(UIWebView *)webView2
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)
navigationType
Callback
          window.location.href



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

                  [webview loadData]
Callback
          window.location.href



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

                  [webview loadData]

- (NSString *)stringByEvaluatingJavaScriptFromString:
(NSString *)script;
Form

Iframe

Script

          webview
  cache
Javascript call ObjC
Read The F**king SourceCode.

https://github.com/linluxiang/
JavascriptCallObjCExample

More Related Content

What's hot (20)

The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
Domenic Denicola
 
Python Code Camp for Professionals 2/4
Python Code Camp for Professionals 2/4Python Code Camp for Professionals 2/4
Python Code Camp for Professionals 2/4
DEVCON
 
What happens in laravel 4 bootstraping
What happens in laravel 4 bootstrapingWhat happens in laravel 4 bootstraping
What happens in laravel 4 bootstraping
Jace Ju
 
TDD of HTTP Clients With WebMock
TDD of HTTP Clients With WebMockTDD of HTTP Clients With WebMock
TDD of HTTP Clients With WebMock
Bartosz Blimke
 
Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Webエンジニアから見たiOS5
Webエンジニアから見たiOS5
Satoshi Asano
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
Michael Girouard
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
FDConf
 
Testing http calls with Webmock and VCR
Testing http calls with Webmock and VCRTesting http calls with Webmock and VCR
Testing http calls with Webmock and VCR
Kerry Buckley
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Tsuyoshi Yamamoto
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Kenji Tanaka
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
DEVCON
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
Websecurify
 
Client server part 12
Client server part 12Client server part 12
Client server part 12
fadlihulopi
 
Nevermore Unit Testing
Nevermore Unit TestingNevermore Unit Testing
Nevermore Unit Testing
Ihsan Fauzi Rahman
 
Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
Caesar Chi
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
Gabriele Lana
 
HTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranHTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - Altran
Robert Nyman
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
Thomas Weinert
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
Domenic Denicola
 
Python Code Camp for Professionals 2/4
Python Code Camp for Professionals 2/4Python Code Camp for Professionals 2/4
Python Code Camp for Professionals 2/4
DEVCON
 
What happens in laravel 4 bootstraping
What happens in laravel 4 bootstrapingWhat happens in laravel 4 bootstraping
What happens in laravel 4 bootstraping
Jace Ju
 
TDD of HTTP Clients With WebMock
TDD of HTTP Clients With WebMockTDD of HTTP Clients With WebMock
TDD of HTTP Clients With WebMock
Bartosz Blimke
 
Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Webエンジニアから見たiOS5
Webエンジニアから見たiOS5
Satoshi Asano
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
FDConf
 
Testing http calls with Webmock and VCR
Testing http calls with Webmock and VCRTesting http calls with Webmock and VCR
Testing http calls with Webmock and VCR
Kerry Buckley
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Tsuyoshi Yamamoto
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Kenji Tanaka
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
DEVCON
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
Websecurify
 
Client server part 12
Client server part 12Client server part 12
Client server part 12
fadlihulopi
 
Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
Caesar Chi
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
Gabriele Lana
 
HTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranHTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - Altran
Robert Nyman
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
Thomas Weinert
 

Similar to Javascript call ObjC (20)

UIWebView Tips
UIWebView TipsUIWebView Tips
UIWebView Tips
Katsumi Kishikawa
 
Gdg dev fest hybrid apps your own mini-cordova
Gdg dev fest hybrid apps  your own mini-cordovaGdg dev fest hybrid apps  your own mini-cordova
Gdg dev fest hybrid apps your own mini-cordova
Ayman Mahfouz
 
Hybrid apps - Your own mini Cordova
Hybrid apps - Your own mini CordovaHybrid apps - Your own mini Cordova
Hybrid apps - Your own mini Cordova
Ayman Mahfouz
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
Ayush Sharma
 
React native by example by Vadim Ruban
React native by example by Vadim RubanReact native by example by Vadim Ruban
React native by example by Vadim Ruban
Lohika_Odessa_TechTalks
 
125 고성능 web view-deview 2013 발표 자료_공유용
125 고성능 web view-deview 2013 발표 자료_공유용125 고성능 web view-deview 2013 발표 자료_공유용
125 고성능 web view-deview 2013 발표 자료_공유용
NAVER D2
 
PhoneGap_Javakuche0612
PhoneGap_Javakuche0612PhoneGap_Javakuche0612
PhoneGap_Javakuche0612
Yuhei Miyazato
 
Writing JavaScript for C# Blazor.pptx
Writing JavaScript for C# Blazor.pptxWriting JavaScript for C# Blazor.pptx
Writing JavaScript for C# Blazor.pptx
Ed Charbeneau
 
A portlet-API based approach for application integration
A portlet-API based approach for application integrationA portlet-API based approach for application integration
A portlet-API based approach for application integration
whabicht
 
Intro to Sail.js
Intro to Sail.jsIntro to Sail.js
Intro to Sail.js
Nicholas McClay
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
vito jeng
 
Scripting GeoServer
Scripting GeoServerScripting GeoServer
Scripting GeoServer
Jared Erickson
 
Orbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case StudyOrbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case Study
Mark Meeker
 
Finch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with FinagleFinch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with Finagle
Vladimir Kostyukov
 
[22]Efficient and Testable MVVM pattern
[22]Efficient and Testable MVVM pattern[22]Efficient and Testable MVVM pattern
[22]Efficient and Testable MVVM pattern
NAVER Engineering
 
Quickly function add by Eclipse Monkey
Quickly function add by Eclipse MonkeyQuickly function add by Eclipse Monkey
Quickly function add by Eclipse Monkey
bose999
 
Lift 2 0
Lift 2 0Lift 2 0
Lift 2 0
SO
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
Paweł Kowalczuk
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
Robert Nyman
 
5.node js
5.node js5.node js
5.node js
Geunhyung Kim
 
Gdg dev fest hybrid apps your own mini-cordova
Gdg dev fest hybrid apps  your own mini-cordovaGdg dev fest hybrid apps  your own mini-cordova
Gdg dev fest hybrid apps your own mini-cordova
Ayman Mahfouz
 
Hybrid apps - Your own mini Cordova
Hybrid apps - Your own mini CordovaHybrid apps - Your own mini Cordova
Hybrid apps - Your own mini Cordova
Ayman Mahfouz
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
Ayush Sharma
 
125 고성능 web view-deview 2013 발표 자료_공유용
125 고성능 web view-deview 2013 발표 자료_공유용125 고성능 web view-deview 2013 발표 자료_공유용
125 고성능 web view-deview 2013 발표 자료_공유용
NAVER D2
 
PhoneGap_Javakuche0612
PhoneGap_Javakuche0612PhoneGap_Javakuche0612
PhoneGap_Javakuche0612
Yuhei Miyazato
 
Writing JavaScript for C# Blazor.pptx
Writing JavaScript for C# Blazor.pptxWriting JavaScript for C# Blazor.pptx
Writing JavaScript for C# Blazor.pptx
Ed Charbeneau
 
A portlet-API based approach for application integration
A portlet-API based approach for application integrationA portlet-API based approach for application integration
A portlet-API based approach for application integration
whabicht
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
vito jeng
 
Orbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case StudyOrbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case Study
Mark Meeker
 
Finch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with FinagleFinch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with Finagle
Vladimir Kostyukov
 
[22]Efficient and Testable MVVM pattern
[22]Efficient and Testable MVVM pattern[22]Efficient and Testable MVVM pattern
[22]Efficient and Testable MVVM pattern
NAVER Engineering
 
Quickly function add by Eclipse Monkey
Quickly function add by Eclipse MonkeyQuickly function add by Eclipse Monkey
Quickly function add by Eclipse Monkey
bose999
 
Lift 2 0
Lift 2 0Lift 2 0
Lift 2 0
SO
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
Robert Nyman
 
Ad

Javascript call ObjC

  • 4. HTML JS Objc
  • 5. HTML JS Objc UIWebView
  • 8. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame {
  • 9. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame { ! [windowObject setValue:localcall forKey:@"localcall"];
  • 10. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame { ! [windowObject setValue:localcall forKey:@"localcall"];
  • 11. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame { ! [windowObject setValue:localcall forKey:@"localcall"]; }
  • 12. JS Global - (void)webView:(id)sender didClearWindowObject:(id) windowObject forFrame:(WebFrame*)frame { ! [windowObject setValue:localcall forKey:@"localcall"]; } + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
  • 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. 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
  • 15. 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
  • 17. Apple
  • 18. Apple + (BOOL)isSelectorExcludedFromWebScript: (SEL)aSelector aSelector
  • 28. RPC
  • 29. RPC http://localcall/func_name? argument=”a_json_string”
  • 30. RPC http://localcall/func_name? argument=”a_json_string”
  • 31. Ajax
  • 35. Ajax XMLHttpRequest Cache - (NSCachedURLResponse *)cachedResponseForRequest: (NSURLRequest *)request
  • 39. Callback window.location.href - (BOOL)webView:(UIWebView *)webView2 shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType) navigationType
  • 40. Callback window.location.href - (BOOL)webView:(UIWebView *)webView2 shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType) navigationType [webview loadData]
  • 41. Callback window.location.href - (BOOL)webView:(UIWebView *)webView2 shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType) navigationType [webview loadData] - (NSString *)stringByEvaluatingJavaScriptFromString: (NSString *)script;
  • 42. Form Iframe Script webview cache
  • 44. Read The F**king SourceCode. https://github.com/linluxiang/ JavascriptCallObjCExample