SlideShare ist ein Scribd-Unternehmen logo
1 von 76
Offline Mode
Overcome your fear of implementing
in your apps
www.addofflinemode.com
Offline Mode
Overcome your fear of implementing
in your apps
www.addofflinemode.com
Marin Todorov
(me)
raywenderlich.com
Today you will
See common offline mode fails and wins
Draw a lot of good advice in the process
Finally have a look at few tools
Connected apps
web services
Internet in your pocket
Web services in the cloud
Photo credit: Flickr, Torkild RetvedtPhoto credit: Flickr, Tim Bates
…
Photo credit: Flickr, Torkild RetvedtPhoto credit: Flickr, Marcin Kargol
Oops (no connection)
Maybe?
Ehm?
offline gprs/edge
Awesome :)
Awesome :)
- offline
- bad connectivity
- online
3 modes
- offline
3 modes
- bad connectivity
3 modes
CTTelephonyNetworkInfo currentRadioAccessTechnology
CTRadioAccessTechnologyGPRS
CTRadioAccessTechnologyEdge
CTRadioAccessTechnologyLTE
CTRadioAccessTechnologyDidChangeNotification
- online
3 modes
current step
steps top pre-fetch
- rely on what makes sense
UI wise
How to handle offline
mode
There is no universal solution
THE END
- asses the problem
- evaluate the solution
- code
3 steps
in this order please!
Klout
Klout
NSUserDefaults
name
score
4 last updates
2 last connections
JSON
Klout
Online?
Start
Fetch JSON
UI Code
Done
Start
Fetch JSON
UI Code
Done
Local JSON
Store locally
YESNO
Simple solution for a simple problem
First asses, then evaluate, then code
York cinemas
York cinemas
cinemas in Berlin - these change once a year
!
film schedule changes every thursday
!
static information - practically doesn’t change
!
ticket reservations
Photo credit: Flickr, Tobias Abel Photo credit: Flickr, InSapphoWeTrust
12 cinema photos + their names + coordinates
25 film posters + film names
30 movie times for all cinemas
!
7KB sqlite file
2MB of photos
!
=
!
< 1 Facebook photo in size
20.03 Thu Sat 27.03 Thu
Check this out York cinemas!
This
week?
Start
Read sqlite database
UI Code
Done
Start
Fetch 1 file
UI Code
Done
YES
NO
Read sqlite database
The problem definition contained the solution
Sqlite database is a single file
You don’t need past data
How about ticket reservations?
You got to to some things online!
You can still do SOMETHING
A stock trading app
price changes all the time
!
displays historical data
!
allows for real-time buying/selling
price changes all the time
!
displays historical data
!
allows for real-time buying/selling
Past data does not change…
14:40 14:50 15:00
14:30 14:40 14:50
14:40 14:50 15:00
Time on plane
14:50 15:00
Time on plane
BUY
3 hrs
For long lists - use sqlite
AAPL!
123456 11.6 10.5
123459 11.5 10.5
123460 12.0 11.0
123470 14.0 11.5
123490 14.0 10.5
Easy to sync to local database
server database JSON local sqlite
AAPL!
!
!
!
123470 14.0 11.5
123490 14.0 10.5
aapl
keep ids from the server
How to fetch the delta data?
14:40 14:50 15:00
+ tokenA + tokenB + tokenC
+ tokenA + tokenB
Facebook
posts come in all the time
!
posting in not time crucial
!
chat with friends
!
location check-in
14:40 14:50 13:20
Time on plane
14:40 14:50 13:20
Time on plane
OMG! Great flight
attendants on the
flight to Lisbon!
Core Data = power + pain
You need to recreate the relationships
Migration strategy
What’s the foreseeable outcome of the create/edit
operations?
Data validation
Cache the create operation data
3 ways to store temporary objects
!
1. create the new objects, store them using NSCoding
2. create a separate store for pending objects
3. use existing store, but use ids < 0
How to change your app
architecture
cloud
Network layer
REST
JSON RPC
JSON API
XML? plist?
Connectivity
User Interface
data storage
NSCoding
sqlite3
Core Data
Cache
file system
Core Data
file storage
You probably have this setup
cloud
Network layer
REST
JSON RPC
JSON API
XML? plist?
Connectivity
User Interface
data storage
NSCoding
sqlite3
Core Data
Cache
file system
Core Data
file storage
You want to have this setup
Prefer reading from local source,
update local source from Internet
Power tools
network, storage, UI …
sorry, iPhone only
CoreTelephony.framework
CTTelephonyNetworkInfo -> currentRadioAccessTechnology
!
CTTelephonyNetworkInfo -> subscriberCellularProvider.isoCountryCode
!
NSURLSession
NSURLSession
CloudCode Cookie policy
Auth policy
Caching policy
Storing files
Timeouts
etc. etc.
NSURLSessionConfiguration
Reachability
https://github.com/tonymillion/Reachability
!
arc, gdc, ios/osx, maximum wins
reach	
  =	
  [Reachability	
  reachabilityWithHostname:@"www.addofflinemode.com"];	
  
reach.unreachableBlock	
  =	
  ^(Reachability*reach)	
  
{	
  
	
  	
  	
  	
  NSLog(@"UNREACHABLE!");	
  
};
JSONModel
https://github.com/icanzilb/JSONModel
!
model classes, validation, data conversion, etc.
JSONModel
{“id”:1, “name”:”Marin”}
NSNumber* id;
NSString* name;
NSManagedObject
Model
JSON
Core Data
NSFetchedResultsController
!
Core Data Editor
Image: http://thermal-core.com/CoreDataEditor/
Core Data
TBCoreDataStore!
!
http://robots.thoughtbot.com/core-data
Main Queue!
context
Background Queue!
context read
write
merge
Internet!
JSON
FMDB
https://github.com/ccgus/fmdb
!
Objc sqlite made easy
FMResultSet	
  *s	
  =	
  [db	
  executeQuery:@"SELECT	
  *	
  FROM	
  myTable"];	
  
while	
  ([s	
  next])	
  {	
  
	
  	
  	
  	
  //retrieve	
  values	
  for	
  each	
  record	
  
}
NSCoding
NSData* encodedData = [NSKeyedArchiver archivedDataWithRootObject: myObject];
[encodedData writeToURL:localFileURL atomically:YES];
Cache
simpler cache library - EGOCache
https://github.com/enormego/EGOCache
image caching - FastImageCache
https://github.com/path/FastImageCache
[[EGOCache globalCache] setObject:JSONResponse forKey:@"cachedJSON"];
[[EGOCache globalCache] setImage:myImage forKey:@"photo" 

withTimeoutInterval:60*60];
Sequencer
https://github.com/berzniz/Sequencer
!
async flow control
Get X Post Y Location Update UI
[sequencer enqueueStep:^(id result, SequencerCompletion completion) {
[self testSectionUnloggedGets: nil];
completion(nil);
}];
!
[sequencer enqueueStep:^(id result, SequencerCompletion completion) {
[self postToServer: ^{
completion(nil);
}];
}];
What’s next?
Turn on plane mode and check how your
favorite apps look like
Check how your app looks like (eeek!)
Get in touch, discuss, check out the power-tools
That’s all folks
Offline Mode
Overcome your fear of implementing
in your apps
www.addofflinemode.com

Weitere ähnliche Inhalte

Ähnlich wie Overcome your fear of implementing offline mode in your apps

Evolution of a big data project
Evolution of a big data projectEvolution of a big data project
Evolution of a big data projectMichael Peacock
 
Fanug - Pragmatic Windows Phone Developer
Fanug - Pragmatic Windows Phone DeveloperFanug - Pragmatic Windows Phone Developer
Fanug - Pragmatic Windows Phone DeveloperSam Basu
 
Informix SQL & NoSQL: Putting it all together
Informix SQL & NoSQL: Putting it all togetherInformix SQL & NoSQL: Putting it all together
Informix SQL & NoSQL: Putting it all togetherKeshav Murthy
 
What's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon TalkWhat's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon TalkSam Basu
 
Importance of APIs in the Internet of Things
Importance of APIs in the Internet of ThingsImportance of APIs in the Internet of Things
Importance of APIs in the Internet of ThingsNordic APIs
 
Web performance optimization
Web performance optimizationWeb performance optimization
Web performance optimizationKaliop-slide
 
Offline of web applications
Offline of web applicationsOffline of web applications
Offline of web applicationsFDConf
 
Offline for web - Frontend Dev Conf Minsk 2014
Offline for web - Frontend Dev Conf Minsk 2014Offline for web - Frontend Dev Conf Minsk 2014
Offline for web - Frontend Dev Conf Minsk 2014Jan Jongboom
 
Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?Robert MacLean
 
Final ProjectFinal Project Details Description Given a spec.docx
Final ProjectFinal Project Details Description  Given a spec.docxFinal ProjectFinal Project Details Description  Given a spec.docx
Final ProjectFinal Project Details Description Given a spec.docxAKHIL969626
 
Is your mobile app up to speed softwaresymposium
Is your mobile app up to speed softwaresymposiumIs your mobile app up to speed softwaresymposium
Is your mobile app up to speed softwaresymposiumDoug Sillars
 
Overview Of Parallel Development - Ericnel
Overview Of Parallel Development -  EricnelOverview Of Parallel Development -  Ericnel
Overview Of Parallel Development - Ericnelukdpe
 
Splunk app for stream
Splunk app for stream Splunk app for stream
Splunk app for stream csching
 
WebRTC: A front-end perspective
WebRTC: A front-end perspectiveWebRTC: A front-end perspective
WebRTC: A front-end perspectiveshwetank
 
Introduction to Semantic Web for GIS Practitioners
Introduction to Semantic Web for GIS PractitionersIntroduction to Semantic Web for GIS Practitioners
Introduction to Semantic Web for GIS PractitionersEmanuele Della Valle
 
C# Client to Cloud
C# Client to CloudC# Client to Cloud
C# Client to CloudStuart Lodge
 
WP7 & Azure
WP7 & AzureWP7 & Azure
WP7 & AzureSam Basu
 

Ähnlich wie Overcome your fear of implementing offline mode in your apps (20)

Evolution of a big data project
Evolution of a big data projectEvolution of a big data project
Evolution of a big data project
 
Fanug - Pragmatic Windows Phone Developer
Fanug - Pragmatic Windows Phone DeveloperFanug - Pragmatic Windows Phone Developer
Fanug - Pragmatic Windows Phone Developer
 
Informix SQL & NoSQL: Putting it all together
Informix SQL & NoSQL: Putting it all togetherInformix SQL & NoSQL: Putting it all together
Informix SQL & NoSQL: Putting it all together
 
What's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon TalkWhat's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon Talk
 
Importance of APIs in the Internet of Things
Importance of APIs in the Internet of ThingsImportance of APIs in the Internet of Things
Importance of APIs in the Internet of Things
 
Web performance optimization
Web performance optimizationWeb performance optimization
Web performance optimization
 
Offline of web applications
Offline of web applicationsOffline of web applications
Offline of web applications
 
Offline for web - Frontend Dev Conf Minsk 2014
Offline for web - Frontend Dev Conf Minsk 2014Offline for web - Frontend Dev Conf Minsk 2014
Offline for web - Frontend Dev Conf Minsk 2014
 
Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?
 
Final ProjectFinal Project Details Description Given a spec.docx
Final ProjectFinal Project Details Description  Given a spec.docxFinal ProjectFinal Project Details Description  Given a spec.docx
Final ProjectFinal Project Details Description Given a spec.docx
 
Is your mobile app up to speed softwaresymposium
Is your mobile app up to speed softwaresymposiumIs your mobile app up to speed softwaresymposium
Is your mobile app up to speed softwaresymposium
 
Overview Of Parallel Development - Ericnel
Overview Of Parallel Development -  EricnelOverview Of Parallel Development -  Ericnel
Overview Of Parallel Development - Ericnel
 
Splunk app for stream
Splunk app for stream Splunk app for stream
Splunk app for stream
 
WebRTC: A front-end perspective
WebRTC: A front-end perspectiveWebRTC: A front-end perspective
WebRTC: A front-end perspective
 
Kenta Yasukawa - IoT World 2018
Kenta Yasukawa - IoT World 2018Kenta Yasukawa - IoT World 2018
Kenta Yasukawa - IoT World 2018
 
Introduction to Semantic Web for GIS Practitioners
Introduction to Semantic Web for GIS PractitionersIntroduction to Semantic Web for GIS Practitioners
Introduction to Semantic Web for GIS Practitioners
 
C# Client to Cloud
C# Client to CloudC# Client to Cloud
C# Client to Cloud
 
Liberating your Industrial Data
Liberating your Industrial DataLiberating your Industrial Data
Liberating your Industrial Data
 
WP7 & Azure
WP7 & AzureWP7 & Azure
WP7 & Azure
 
April09SIG_SL3
April09SIG_SL3April09SIG_SL3
April09SIG_SL3
 

Kürzlich hochgeladen

9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 

Kürzlich hochgeladen (7)

9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 

Overcome your fear of implementing offline mode in your apps