Many Apps need to access data online. This talk discusses problems and solutions when accessing remote data with Android and iPhone. After a brief review of a number of frameworks, an approach is outlined to implement data access in a cross-platform manner using a DSL.
13. Detecting Connectivity
States we need to detect:
Device not connected to internet
Connection slow
Server(s) not reachable
Server online, but requested service not available
24. Massaging !!
In-App vs. Online
In-App massaging:
- needs to be rewritten for each platform
- ad-hoc enhancements virtually impossible (iPhone)
Server-side massaging:
- write once, re-use with every app
- problem with authentication (man-in-the-middle)
25. Massaging
Online tools
FeedSanitizer - http://feedsanitizer.appspot.com/
HTML Tidy - http://infohound.net/tidy/
JSONFormatter - http://jsonformatter.curiousconcept.com/
Roll your own
YQL - http://developer.yahoo.com/yql/
Node.js - http://nodejs.org/
Google App Engine - http://code.google.com/appengine/
26. Massaging with
var sponsorImageExpr = /Sponsored by:.*<img.*src="(.*)">?/;
var sponsoredByFilter = new SimpleFilter(function(data) {
! session = data;
! if (session.title.match(sponsorImageExpr)) {
! ! sponsorlogoURL = session.title.match(sponsorImageExpr);
! ! session.sponsorLogoURL = sponsorlogoURL[1];
! ! session.title = session.title.replace(
sponsorImageExpr, '');!!
! }
! return session;
});
var stripHTMLFilter = new SimpleFilter(function(string) {
! return string.replace(/</?[^>]+(>|$)/g, '');
});
var sessionsFilterChain =
! new FilterChain()
! ! .append(sponsoredByFilter)
! ! .append(stripHTMLFilter);
30. Caching
Store in a local SQL database
SQLite - (Android SDK)
OrmLite - http://ormlite.com/
db4o - http://db4o.com/
ActiveAndroid - https://www.activeandroid.com/
AndroidActiveRecord -
http://code.google.com/p/android-active-record/
Store in the local file system
Use cache directory - Context.getCacheDir()
31. Caching
Store in a local SQL database
SQLite - (iPhone SDK)
ActiveRecord - https://github.com/aptiva/activerecord
CoreData - (iPhone SDK)
Store in the local file system
URLCache sample - http://developer.apple.com/
library/ios/#samplecode/URLCache
44. Solution: Use A DSL
Entities
Data View
Mappers Controllers
Entity
Descriptions
DSL
iOS / Objective-C
describes data
model and
mapping rules
Entities
DSL IDE
Transformers Activities
Content
Providers
Android / Java
45. DSL Sample
Fetching Blog Items
entity BlogItem {
String guid
String title
String link
String description
String creator
}
contentprovider Blogposts
returns BlogItem[]
fetches XML
from (FEEDSANITIZER_URL "/sanitize?url=http%3A%2F%2Fblogs.itemis.de%2F
%3Fshowfeed%3D1&format=rss")
selects "rss.channel.item"
49. Image credits
Tower bridge - http://www.flickr.com/photos/anirudhkoul/3499471010/
Little girl with cell - http://www.flickr.com/photos/spitzgogo/286917522/
Gray-haired guy on bench - http://www.flickr.com/photos/mr_t_in_dc/5524143121/
Girl with hoody, texting - http://www.flickr.com/photos/lanier67/2979124681/
Fast girl on bike - http://www.flickr.com/photos/pixel_addict/465394708/
NY Apple Store - http://www.flickr.com/photos/smoovey/3749038495/
Guy driving and texting - http://www.flickr.com/photos/lord-jim/4794895023/
Portraits:
http://www.flickr.com/photos/46914331@N03/4312184861/
http://www.flickr.com/photos/pagedooley/4258558487/
http://www.flickr.com/photos/yuri-samoilov/4105603525/
http://www.flickr.com/photos/adriel_socrates/5560606768/
http://www.flickr.com/photos/adriel_socrates/5560592742/in/photostream/
http://www.flickr.com/photos/kkoshy/4729866481/
http://www.flickr.com/photos/pagedooley/4258558741/
http://www.flickr.com/photos/mescon/3668279183/
http://www.flickr.com/photos/mescon/2984454695/
http://www.flickr.com/photos/ter-burg/428205830/
http://www.flickr.com/photos/eudaimos/2107219904/
Mountains, Lake and Boat - http://www.flickr.com/photos/visulogik/2180603155/
Dead Sea Scrolls - http://www.flickr.com/photos/kjfnjy/5249145754/
Lines of communication - http://www.flickr.com/photos/ruudhein/4442182264/
Satellite dish - http://www.flickr.com/photos/26652703@N02/2502519971/