SlideShare a Scribd company logo
www.priyaontech.com
Native-JS Bridging
Using WKWebViews
Priya Rajagopal
@rajagp
www.priyaontech.com
WebKit
• Rendering/Layout Engine for web content
• Powers Safari & web views (Native Apps)
• JS Processing
• HTML/CSS rendering
• Networking/ Web request response Handling
www.priyaontech.com
Pre iOS8
• UIWebViews
• UIKit.framework
• In-process loading of web content
• Limited
• No JS Nitro optimizations
• Many WebKit capabilities not exposed
• Bridging between Native and JS a pain…
iOS 8
www.priyaontech.com
Modern WebKit
• Unified WebKit Framework across OS X 10.10 & iOS 8
• Safari & Native Apps
• Multi-process Architecture
• web page loaded in a separate process(upto a limit)
• Hardware Accelerated Scrolling (60 fps)
• JS Nitro Engine
• Built-in Navigation Gestures (swipe back/forward, zoom…)
www.priyaontech.com
Modern WebKit
• Simplified Native <->JS Communication
www.priyaontech.com
WKWebView
Replaces UIWebView (iOS)
WKWebView
WKNavigationDelegate
WKUIDelegate
WKBackForwardList
…
WebKit.framework
WKWebViewConfiguration
WKUserContentController
WKPreferences
WKProcessPool
allowsInlineMediaPlayback
mediaPlaybackAllowsAirPlay
….
- (instancetype)initWithFrame:(CGRect)frame configuration:
(WKWebViewConfiguration *)configuration
www.priyaontech.com
Native->JS
• User Scripts (WKUserScript)
• Inject JS into web page that …
• Registers For Events
• Customizes web page behavior
• Calls back into Native
www.priyaontech.com
User Scripts
// Setup WKUserContentController instance
WKUserContentController* userController = [[WKUserContentController
alloc]init];
// Specify when and where and what user script needs to be injected into
the web document
WKUserScript* userScript = [[WKUserScript alloc]initWithSource:myScript
injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
// Add the user script to the WKUserContentController instance
[userController addUserScript:userScript];
// Configure the WKWebViewConfiguration instance with the
WKUserContentController
_webConfig.userContentController = userController;
www.priyaontech.com
JS Evaluation
-
- (void)evaluateJavaScript:(NSString *)javaScriptString
completionHandler:(void (^)(id, NSError *))completionHandler;
www.priyaontech.com
JS->Native
• Script Messages
window.webkit.messageHandlers.<name>.postMessage(<messageBody>)
• Register Script Message Handler in Native
Implement WKScriptMessageHandler Protocol
• JS Objects Auto mapped to Obj-C / Swift
Objects
www.priyaontech.com
Script Messages
// Add a script message handler for receiving "MyEvent" event notifications
posted from the JS document using
window.webkit.messageHandlers.MyEvent.postMessage script message
[userController addScriptMessageHandler:self name:@"MyEvent"];
// Implement WKScriptMessageHandler Protocol
- (void)userContentController:(WKUserContentController
*)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
if ([message.name isEqualToString:@“MyEvent”]) {
// message.body is the Obj-C object
}
}
Demo
https://github.com/rajagp/iOS-WKWebViewBridgeExample-ObjC
https://github.com/rajagp/iOS-WKWebViewBridgeExample-Swift
Thank you!
@rajagp

More Related Content

What's hot

Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usWebpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of us
Stefan Adolf
 
DotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactDotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + react
Chen-Tien Tsai
 
Deep dive into Vue.js
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js
선협 이
 
Vue 淺談前端建置工具
Vue 淺談前端建置工具Vue 淺談前端建置工具
Vue 淺談前端建置工具
andyyou
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
Marcus Hellberg
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
Bob Paulin
 
Vue.js is boring - and that's a good thing
Vue.js is boring - and that's a good thingVue.js is boring - and that's a good thing
Vue.js is boring - and that's a good thing
Joonas Lehtonen
 
JavaFX meetup
JavaFX meetupJavaFX meetup
JavaFX meetup
Eduard Drenth
 
RESTful Web Applications with Apache Sling
RESTful Web Applications with Apache SlingRESTful Web Applications with Apache Sling
RESTful Web Applications with Apache Sling
Bertrand Delacretaz
 
Bundle your modules with Webpack
Bundle your modules with WebpackBundle your modules with Webpack
Bundle your modules with Webpack
Jake Peyser
 
Cloud browser testing with Gradle and Geb
Cloud browser testing with Gradle and GebCloud browser testing with Gradle and Geb
Cloud browser testing with Gradle and Geb
David Carr
 
An Introduction to Vuejs
An Introduction to VuejsAn Introduction to Vuejs
An Introduction to Vuejs
Paddy Lock
 
Webpack
WebpackWebpack
Webpack
Anjali Chawla
 
WebKit Programming in Cocoa
WebKit Programming in CocoaWebKit Programming in Cocoa
WebKit Programming in Cocoa
Jason Harwig
 
Let's run JavaScript Everywhere
Let's run JavaScript EverywhereLet's run JavaScript Everywhere
Let's run JavaScript Everywhere
Tom Croucher
 
"Backbone React Flux" Артем Тритяк
"Backbone React Flux" Артем Тритяк"Backbone React Flux" Артем Тритяк
"Backbone React Flux" Артем Тритяк
Fwdays
 
Performance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsPerformance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React Applications
Denis Izmaylov
 
Isomorphic web application
Isomorphic web applicationIsomorphic web application
Isomorphic web application
Oliver N
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - Webpack
Razvan Rosu
 
ZK framework
ZK frameworkZK framework

What's hot (20)

Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usWebpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of us
 
DotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactDotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + react
 
Deep dive into Vue.js
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js
 
Vue 淺談前端建置工具
Vue 淺談前端建置工具Vue 淺談前端建置工具
Vue 淺談前端建置工具
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
 
Vue.js is boring - and that's a good thing
Vue.js is boring - and that's a good thingVue.js is boring - and that's a good thing
Vue.js is boring - and that's a good thing
 
JavaFX meetup
JavaFX meetupJavaFX meetup
JavaFX meetup
 
RESTful Web Applications with Apache Sling
RESTful Web Applications with Apache SlingRESTful Web Applications with Apache Sling
RESTful Web Applications with Apache Sling
 
Bundle your modules with Webpack
Bundle your modules with WebpackBundle your modules with Webpack
Bundle your modules with Webpack
 
Cloud browser testing with Gradle and Geb
Cloud browser testing with Gradle and GebCloud browser testing with Gradle and Geb
Cloud browser testing with Gradle and Geb
 
An Introduction to Vuejs
An Introduction to VuejsAn Introduction to Vuejs
An Introduction to Vuejs
 
Webpack
WebpackWebpack
Webpack
 
WebKit Programming in Cocoa
WebKit Programming in CocoaWebKit Programming in Cocoa
WebKit Programming in Cocoa
 
Let's run JavaScript Everywhere
Let's run JavaScript EverywhereLet's run JavaScript Everywhere
Let's run JavaScript Everywhere
 
"Backbone React Flux" Артем Тритяк
"Backbone React Flux" Артем Тритяк"Backbone React Flux" Артем Тритяк
"Backbone React Flux" Артем Тритяк
 
Performance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsPerformance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React Applications
 
Isomorphic web application
Isomorphic web applicationIsomorphic web application
Isomorphic web application
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - Webpack
 
ZK framework
ZK frameworkZK framework
ZK framework
 

Viewers also liked

Native Javascript apps with PhoneGap
Native Javascript apps with PhoneGapNative Javascript apps with PhoneGap
Native Javascript apps with PhoneGap
Martin de Keijzer
 
Twitterville
TwittervilleTwitterville
Twitterville
Whitney González
 
Presentación1
Presentación1Presentación1
Presentación1
juanpilar745
 
Theme 4. English Colonies of North America
Theme 4. English Colonies of North AmericaTheme 4. English Colonies of North America
Theme 4. English Colonies of North America
susiehiner
 
Brand value fulfillment_sjw
Brand value fulfillment_sjwBrand value fulfillment_sjw
Brand value fulfillment_sjw
staceyjune
 
Avoiding Pressure Surge Damage In Pipeline Systems I Chem E &amp; Ea
Avoiding Pressure Surge Damage In Pipeline Systems I Chem E &amp; EaAvoiding Pressure Surge Damage In Pipeline Systems I Chem E &amp; Ea
Avoiding Pressure Surge Damage In Pipeline Systems I Chem E &amp; Ea
blenrayaust
 
Alcanar events
Alcanar eventsAlcanar events
Alcanar events
juanpilar745
 
Karate kid!
Karate kid!Karate kid!
Karate kid!
juanpilar745
 
IYSO Team INDIA Voluntary Blood Donors Photographs
IYSO Team INDIA Voluntary Blood Donors PhotographsIYSO Team INDIA Voluntary Blood Donors Photographs
IYSO Team INDIA Voluntary Blood Donors Photographs
BloodDonors
 
Open Innovatie in een KMO
Open Innovatie in een KMOOpen Innovatie in een KMO
Open Innovatie in een KMO
induct
 
Bit, milano 18 febbraio 2011, social media strategy di prodotto regione umbria
Bit, milano 18 febbraio 2011, social media strategy di prodotto regione umbriaBit, milano 18 febbraio 2011, social media strategy di prodotto regione umbria
Bit, milano 18 febbraio 2011, social media strategy di prodotto regione umbria
gianluigibettin
 
Confidently resilient
Confidently resilientConfidently resilient
Confidently resilient
Kilian Widmer
 
The Unredeemed Captive
The Unredeemed CaptiveThe Unredeemed Captive
The Unredeemed Captive
susiehiner
 
Free time in Alcanar
Free time in AlcanarFree time in Alcanar
Free time in Alcanar
juanpilar745
 
The Engineering World Of Thermoplastic Piping
The Engineering World Of Thermoplastic PipingThe Engineering World Of Thermoplastic Piping
The Engineering World Of Thermoplastic Piping
blenrayaust
 
Free time in alcanar
Free time in alcanarFree time in alcanar
Free time in alcanar
juanpilar745
 
Analysis of the questionnaire
Analysis of the questionnaireAnalysis of the questionnaire
Analysis of the questionnaire
sp_gebice
 
Company presentation NIDays 2011
Company presentation NIDays 2011Company presentation NIDays 2011
Company presentation NIDays 2011
induct
 
Orgtiltuyaaaa
OrgtiltuyaaaaOrgtiltuyaaaa
Orgtiltuyaaaa
chodroo
 

Viewers also liked (20)

Native Javascript apps with PhoneGap
Native Javascript apps with PhoneGapNative Javascript apps with PhoneGap
Native Javascript apps with PhoneGap
 
Twitterville
TwittervilleTwitterville
Twitterville
 
Presentación1
Presentación1Presentación1
Presentación1
 
Moodle
MoodleMoodle
Moodle
 
Theme 4. English Colonies of North America
Theme 4. English Colonies of North AmericaTheme 4. English Colonies of North America
Theme 4. English Colonies of North America
 
Brand value fulfillment_sjw
Brand value fulfillment_sjwBrand value fulfillment_sjw
Brand value fulfillment_sjw
 
Avoiding Pressure Surge Damage In Pipeline Systems I Chem E &amp; Ea
Avoiding Pressure Surge Damage In Pipeline Systems I Chem E &amp; EaAvoiding Pressure Surge Damage In Pipeline Systems I Chem E &amp; Ea
Avoiding Pressure Surge Damage In Pipeline Systems I Chem E &amp; Ea
 
Alcanar events
Alcanar eventsAlcanar events
Alcanar events
 
Karate kid!
Karate kid!Karate kid!
Karate kid!
 
IYSO Team INDIA Voluntary Blood Donors Photographs
IYSO Team INDIA Voluntary Blood Donors PhotographsIYSO Team INDIA Voluntary Blood Donors Photographs
IYSO Team INDIA Voluntary Blood Donors Photographs
 
Open Innovatie in een KMO
Open Innovatie in een KMOOpen Innovatie in een KMO
Open Innovatie in een KMO
 
Bit, milano 18 febbraio 2011, social media strategy di prodotto regione umbria
Bit, milano 18 febbraio 2011, social media strategy di prodotto regione umbriaBit, milano 18 febbraio 2011, social media strategy di prodotto regione umbria
Bit, milano 18 febbraio 2011, social media strategy di prodotto regione umbria
 
Confidently resilient
Confidently resilientConfidently resilient
Confidently resilient
 
The Unredeemed Captive
The Unredeemed CaptiveThe Unredeemed Captive
The Unredeemed Captive
 
Free time in Alcanar
Free time in AlcanarFree time in Alcanar
Free time in Alcanar
 
The Engineering World Of Thermoplastic Piping
The Engineering World Of Thermoplastic PipingThe Engineering World Of Thermoplastic Piping
The Engineering World Of Thermoplastic Piping
 
Free time in alcanar
Free time in alcanarFree time in alcanar
Free time in alcanar
 
Analysis of the questionnaire
Analysis of the questionnaireAnalysis of the questionnaire
Analysis of the questionnaire
 
Company presentation NIDays 2011
Company presentation NIDays 2011Company presentation NIDays 2011
Company presentation NIDays 2011
 
Orgtiltuyaaaa
OrgtiltuyaaaaOrgtiltuyaaaa
Orgtiltuyaaaa
 

Similar to Native-Javascript Bridging Using WKWebViews in iOS8

Hardware Acceleration in WebKit
Hardware Acceleration in WebKitHardware Acceleration in WebKit
Hardware Acceleration in WebKit
Joone Hur
 
Developing for the mobile web
Developing for the mobile webDeveloping for the mobile web
Developing for the mobile web
joeysim
 
CTU June 2011 - Things that Every ASP.NET Developer Should Know
CTU June 2011 - Things that Every ASP.NET Developer Should KnowCTU June 2011 - Things that Every ASP.NET Developer Should Know
CTU June 2011 - Things that Every ASP.NET Developer Should Know
Spiffy
 
Going mobile with RichFaces
Going mobile with RichFacesGoing mobile with RichFaces
Going mobile with RichFaces
Lukáš Fryč
 
Sug bangalore - headless jss
Sug bangalore - headless jssSug bangalore - headless jss
Sug bangalore - headless jss
Anindita Bhattacharya
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
Timothy Fisher
 
Optimizing React Native views for pre-animation
Optimizing React Native views for pre-animationOptimizing React Native views for pre-animation
Optimizing React Native views for pre-animation
ModusJesus
 
Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
Bob German
 
DEFCON 23 - Nadeem Douba - Using WebKit to Own the Web
DEFCON 23 - Nadeem Douba - Using WebKit to Own the WebDEFCON 23 - Nadeem Douba - Using WebKit to Own the Web
DEFCON 23 - Nadeem Douba - Using WebKit to Own the Web
Felipe Prado
 
DEFCON-23-Nadeem-Douba-BurpKit
DEFCON-23-Nadeem-Douba-BurpKitDEFCON-23-Nadeem-Douba-BurpKit
DEFCON-23-Nadeem-Douba-BurpKit
Nadeem Douba
 
Mobile App Development
Mobile App DevelopmentMobile App Development
Mobile App Development
Chris Morrell
 
WebKit Clutter Port Present and Future; WebKitGtk Status and Roadmap to WebKi...
WebKit Clutter Port Present and Future; WebKitGtk Status and Roadmap to WebKi...WebKit Clutter Port Present and Future; WebKitGtk Status and Roadmap to WebKi...
WebKit Clutter Port Present and Future; WebKitGtk Status and Roadmap to WebKi...
Igalia
 
Ajax basics
Ajax basicsAjax basics
Ajax basics
Vel004
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
David Xi Peng Yang
 
Where does Laravel fit in the Jamstack concept?
Where does Laravel fit in the Jamstack concept?Where does Laravel fit in the Jamstack concept?
Where does Laravel fit in the Jamstack concept?
Tihomir Opačić
 
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Corey Clark, Ph.D.
 
Building Real-World Dojo Web Applications
Building Real-World Dojo Web ApplicationsBuilding Real-World Dojo Web Applications
Building Real-World Dojo Web Applications
Andrew Ferrier
 
Seattle JS Meetup - Grunt EJS Static Presentation
Seattle JS Meetup - Grunt EJS Static PresentationSeattle JS Meetup - Grunt EJS Static Presentation
Seattle JS Meetup - Grunt EJS Static Presentation
Shae Kuronen
 
Building API in the cloud using Azure Functions
Building API in the cloud using Azure FunctionsBuilding API in the cloud using Azure Functions
Building API in the cloud using Azure Functions
Aleksandar Bozinovski
 
Cross browser web development
Cross browser web developmentCross browser web development
Cross browser web development
Ilya Starostin
 

Similar to Native-Javascript Bridging Using WKWebViews in iOS8 (20)

Hardware Acceleration in WebKit
Hardware Acceleration in WebKitHardware Acceleration in WebKit
Hardware Acceleration in WebKit
 
Developing for the mobile web
Developing for the mobile webDeveloping for the mobile web
Developing for the mobile web
 
CTU June 2011 - Things that Every ASP.NET Developer Should Know
CTU June 2011 - Things that Every ASP.NET Developer Should KnowCTU June 2011 - Things that Every ASP.NET Developer Should Know
CTU June 2011 - Things that Every ASP.NET Developer Should Know
 
Going mobile with RichFaces
Going mobile with RichFacesGoing mobile with RichFaces
Going mobile with RichFaces
 
Sug bangalore - headless jss
Sug bangalore - headless jssSug bangalore - headless jss
Sug bangalore - headless jss
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
Optimizing React Native views for pre-animation
Optimizing React Native views for pre-animationOptimizing React Native views for pre-animation
Optimizing React Native views for pre-animation
 
Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
 
DEFCON 23 - Nadeem Douba - Using WebKit to Own the Web
DEFCON 23 - Nadeem Douba - Using WebKit to Own the WebDEFCON 23 - Nadeem Douba - Using WebKit to Own the Web
DEFCON 23 - Nadeem Douba - Using WebKit to Own the Web
 
DEFCON-23-Nadeem-Douba-BurpKit
DEFCON-23-Nadeem-Douba-BurpKitDEFCON-23-Nadeem-Douba-BurpKit
DEFCON-23-Nadeem-Douba-BurpKit
 
Mobile App Development
Mobile App DevelopmentMobile App Development
Mobile App Development
 
WebKit Clutter Port Present and Future; WebKitGtk Status and Roadmap to WebKi...
WebKit Clutter Port Present and Future; WebKitGtk Status and Roadmap to WebKi...WebKit Clutter Port Present and Future; WebKitGtk Status and Roadmap to WebKi...
WebKit Clutter Port Present and Future; WebKitGtk Status and Roadmap to WebKi...
 
Ajax basics
Ajax basicsAjax basics
Ajax basics
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
 
Where does Laravel fit in the Jamstack concept?
Where does Laravel fit in the Jamstack concept?Where does Laravel fit in the Jamstack concept?
Where does Laravel fit in the Jamstack concept?
 
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
 
Building Real-World Dojo Web Applications
Building Real-World Dojo Web ApplicationsBuilding Real-World Dojo Web Applications
Building Real-World Dojo Web Applications
 
Seattle JS Meetup - Grunt EJS Static Presentation
Seattle JS Meetup - Grunt EJS Static PresentationSeattle JS Meetup - Grunt EJS Static Presentation
Seattle JS Meetup - Grunt EJS Static Presentation
 
Building API in the cloud using Azure Functions
Building API in the cloud using Azure FunctionsBuilding API in the cloud using Azure Functions
Building API in the cloud using Azure Functions
 
Cross browser web development
Cross browser web developmentCross browser web development
Cross browser web development
 

Native-Javascript Bridging Using WKWebViews in iOS8