• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Overcome your fear of implementing offline mode in your apps
 

Overcome your fear of implementing offline mode in your apps

on

  • 327 views

Way too many apps on the App Store totally break when you loose connectivity. Have a look at some study cases and hopefully by the end you will figure out that implementing offline mode in your app is ...

Way too many apps on the App Store totally break when you loose connectivity. Have a look at some study cases and hopefully by the end you will figure out that implementing offline mode in your app is not that difficult at all.

Statistics

Views

Total Views
327
Views on SlideShare
251
Embed Views
76

Actions

Likes
0
Downloads
0
Comments
0

2 Embeds 76

http://www.touch-code-magazine.com 68
http://www.slideee.com 8

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Overcome your fear of implementing offline mode in your apps Overcome your fear of implementing offline mode in your apps Presentation Transcript

    • 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