SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Don’t Gap The Bridge




Bridge The Gap
Piotr Steininger

• Software enthusiast and architect
• Background: PHP, JEE, ExtJS, SproutCore
• Worked with: GEICO, FINRA, Time
• SproutCore: SI for Android, Fortune500+
JS-to-Native-to-JS

• Challenge: access to Mobile phone features
 • accelerometer
 • local storage
 • CAMERA, Microphone, etc
• Solutions: PhoneGap, Titanium ?
PhoneGap - Features
• Supports 6 platforms
• Features
 • Accelerometer, Compass, GPS
 • Camera, Audio
 • Storage/File System
 • Notifications (sound, vibration)
PhoneGap - Issues
• Tries to cover too much ground
• Overly complex
• Excessive amount of code
• Slow (due to the above)
• Many features already in WebKit
• Breaks SproutCore !
The Project
•   SI Magazine

•   Reader app, rich UI

•   Support various content
    types

•   Run on iPhone and
    Android

•   Limited JS-native needs
Project Needs
• Access to Native Debug console
• Secure off-line storage and caching of data
• 2-way JS-native Bridge with callbacks
• Change native controls based on JS UI
  changes
• Ability to execute select native commands
Problems
• PhoneGap does not work (well) with
  Sproutcore
 • Uses custom URL schemes on iOS to
    send commands to native
 • Causes split second loss of access to
    DOM
 • Sproutcore blows up silently during
    rendering and stops the app
More Problems

• Works differently on Android
 • Uses a long-polling AJaX server (?!?!)
• Bloat (!) - too many features
• Slowdowns
• Too much complexity
Solutions

• Step 1: on iOS change transport layer
• Step 2: remove 99% of PhoneGap
• Step 3: Keep it simple
iOS

• Used SC.Request instead of
  window.location.url
• Intercepted psuedo-XHR requests in iOS
  default cache
• Rewrote requests and redirected to PG
  command infrastructure
iOS Details

• Extend NSURLCache
• Override cachedResponse method to
  intercept URLs
• Used http://gap/... instead of gap://....
• New JS-to-Native API + callback support
iOS Details
@interface MyURLCache : NSURLCache {
}

@implementation MyURLCache
- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request {

 NSString *pathString = [[request URL] absoluteString];


 if ([pathString rangeOfString:@"http://gap/"].location != NSNotFound) {

     pathString =
    [pathString stringByReplacingOccurrencesOfString:@"http://gap/" withString:@"gap://"];

 
    NSNotification *n =
   [NSNotification notificationWithName:DidReceiveJSNotification object:pathString];

  [[NSNotificationCenter defaultCenter]
    performSelectorOnMainThread:@selector(postNotification:)

 
      withObject:n waitUntilDone:NO];

 }


 return nil;
}
iOS Details
//in app delegate didFinishLaunchingWithOptions:

MyURLCache *cache = [[MyURLCache alloc] init];

NSURLCache setSharedURLCache:cache];

[cache release];
Android

• No part of PhoneGap used
• Java Class and exposed to WebView
• Separate and simpler JS API to match iOS
  (same API different guts)
Android Details
public class NativeInterface {
   private static final String TAG = "NativeInterface";
   private WebView appView;
   private App activity;
   public NativeSupport(WebView v, App activity) {
       appView = v;
       activity = activity;
   }
   ...
}
Android Details
public class App extends Activity {
private WebView webView;
private NativeInterface nativeInterface;
...
public void onCreate(Bundle savedInstanceState) {
  nativeInterface = new NativeInterface(webView, this);
  webView.addJavascriptInterface(nativeInterface,"NativeInterface");
}

...
webView.loadUrl("javascript: SCApp.function(...);”);
Conclusion

• There IS a NoGap way
• Pick your battles wisely!
• Evaluate your needs and decide
• iOS and Android expert on your team
Q&A

• Piotr (Peter) Steininger
• Contact Info:
 • http://about.me/piotr.steininger
 • piotr@tapangi.com

Weitere ähnliche Inhalte

Ähnlich wie Bridge the gap

An overview of mobile html + java script frameworks
An overview of mobile html + java script frameworksAn overview of mobile html + java script frameworks
An overview of mobile html + java script frameworks
Sasha dos Santos
 
Phonegap for Engineers
Phonegap for EngineersPhonegap for Engineers
Phonegap for Engineers
Brian LeRoux
 
iOS 2 - The practical Stuff
iOS 2 - The practical StuffiOS 2 - The practical Stuff
iOS 2 - The practical Stuff
Petr Dvorak
 
Drupal and mobile devices komelin konstanin (eng)
Drupal and mobile devices komelin konstanin (eng)Drupal and mobile devices komelin konstanin (eng)
Drupal and mobile devices komelin konstanin (eng)
drupalconf
 
Mobile App Development
Mobile App DevelopmentMobile App Development
Mobile App Development
Chris Morrell
 

Ähnlich wie Bridge the gap (20)

ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better NetworkingITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
ITT 2014 - Erik Hellmann - Android Programming - Smarter and Better Networking
 
e10sとアプリ間通信
e10sとアプリ間通信e10sとアプリ間通信
e10sとアプリ間通信
 
An overview of mobile html + java script frameworks
An overview of mobile html + java script frameworksAn overview of mobile html + java script frameworks
An overview of mobile html + java script frameworks
 
Phonegap for Engineers
Phonegap for EngineersPhonegap for Engineers
Phonegap for Engineers
 
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
 
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in PracticeOpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
 
iOS 2 - The practical Stuff
iOS 2 - The practical StuffiOS 2 - The practical Stuff
iOS 2 - The practical Stuff
 
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
Architecture app
Architecture appArchitecture app
Architecture app
 
PhoneGap - Now and the Future
PhoneGap - Now and the FuturePhoneGap - Now and the Future
PhoneGap - Now and the Future
 
What’s new in aNdroid [Google I/O Extended Bangkok 2016]
What’s new in aNdroid [Google I/O Extended Bangkok 2016]What’s new in aNdroid [Google I/O Extended Bangkok 2016]
What’s new in aNdroid [Google I/O Extended Bangkok 2016]
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Txjs
TxjsTxjs
Txjs
 
Top 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud DevelopersTop 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud Developers
 
Drupal and mobile devices komelin konstanin (eng)
Drupal and mobile devices komelin konstanin (eng)Drupal and mobile devices komelin konstanin (eng)
Drupal and mobile devices komelin konstanin (eng)
 
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
 
移动端Web app开发
移动端Web app开发移动端Web app开发
移动端Web app开发
 
Mobile App Development
Mobile App DevelopmentMobile App Development
Mobile App Development
 
Никита Корчагин - Introduction to Apple iOS Development.
Никита Корчагин - Introduction to Apple iOS Development.Никита Корчагин - Introduction to Apple iOS Development.
Никита Корчагин - Introduction to Apple iOS Development.
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

Bridge the gap

  • 1. Don’t Gap The Bridge Bridge The Gap
  • 2. Piotr Steininger • Software enthusiast and architect • Background: PHP, JEE, ExtJS, SproutCore • Worked with: GEICO, FINRA, Time • SproutCore: SI for Android, Fortune500+
  • 3. JS-to-Native-to-JS • Challenge: access to Mobile phone features • accelerometer • local storage • CAMERA, Microphone, etc • Solutions: PhoneGap, Titanium ?
  • 4. PhoneGap - Features • Supports 6 platforms • Features • Accelerometer, Compass, GPS • Camera, Audio • Storage/File System • Notifications (sound, vibration)
  • 5. PhoneGap - Issues • Tries to cover too much ground • Overly complex • Excessive amount of code • Slow (due to the above) • Many features already in WebKit • Breaks SproutCore !
  • 6. The Project • SI Magazine • Reader app, rich UI • Support various content types • Run on iPhone and Android • Limited JS-native needs
  • 7. Project Needs • Access to Native Debug console • Secure off-line storage and caching of data • 2-way JS-native Bridge with callbacks • Change native controls based on JS UI changes • Ability to execute select native commands
  • 8. Problems • PhoneGap does not work (well) with Sproutcore • Uses custom URL schemes on iOS to send commands to native • Causes split second loss of access to DOM • Sproutcore blows up silently during rendering and stops the app
  • 9. More Problems • Works differently on Android • Uses a long-polling AJaX server (?!?!) • Bloat (!) - too many features • Slowdowns • Too much complexity
  • 10. Solutions • Step 1: on iOS change transport layer • Step 2: remove 99% of PhoneGap • Step 3: Keep it simple
  • 11. iOS • Used SC.Request instead of window.location.url • Intercepted psuedo-XHR requests in iOS default cache • Rewrote requests and redirected to PG command infrastructure
  • 12. iOS Details • Extend NSURLCache • Override cachedResponse method to intercept URLs • Used http://gap/... instead of gap://.... • New JS-to-Native API + callback support
  • 13. iOS Details @interface MyURLCache : NSURLCache { } @implementation MyURLCache - (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request { NSString *pathString = [[request URL] absoluteString]; if ([pathString rangeOfString:@"http://gap/"].location != NSNotFound) { pathString = [pathString stringByReplacingOccurrencesOfString:@"http://gap/" withString:@"gap://"]; NSNotification *n = [NSNotification notificationWithName:DidReceiveJSNotification object:pathString]; [[NSNotificationCenter defaultCenter] performSelectorOnMainThread:@selector(postNotification:) withObject:n waitUntilDone:NO]; } return nil; }
  • 14. iOS Details //in app delegate didFinishLaunchingWithOptions: MyURLCache *cache = [[MyURLCache alloc] init]; NSURLCache setSharedURLCache:cache]; [cache release];
  • 15. Android • No part of PhoneGap used • Java Class and exposed to WebView • Separate and simpler JS API to match iOS (same API different guts)
  • 16. Android Details public class NativeInterface { private static final String TAG = "NativeInterface"; private WebView appView; private App activity; public NativeSupport(WebView v, App activity) { appView = v; activity = activity; } ... }
  • 17. Android Details public class App extends Activity { private WebView webView; private NativeInterface nativeInterface; ... public void onCreate(Bundle savedInstanceState) { nativeInterface = new NativeInterface(webView, this); webView.addJavascriptInterface(nativeInterface,"NativeInterface"); } ... webView.loadUrl("javascript: SCApp.function(...);”);
  • 18. Conclusion • There IS a NoGap way • Pick your battles wisely! • Evaluate your needs and decide • iOS and Android expert on your team
  • 19. Q&A • Piotr (Peter) Steininger • Contact Info: • http://about.me/piotr.steininger • piotr@tapangi.com

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n