ios background sync (a.k.a. fetch)

12
Background Sync Goran Blažič a.k.a. goranche facebook - twitter - github - linkedin - @me.com

Upload: goran-blazic

Post on 16-Jul-2015

86 views

Category:

Technology


3 download

TRANSCRIPT

Background SyncGoran Blažiča.k.a. goranche

facebook - twitter - github - linkedin - @me.com

So, who are you again?• pro software engineer for 2 decades

• iOS / OS X oriented for the past 6 years most of that time freelancing

• co-founder of and coach at CodeCatz major project: http://events.codeweek.eu

• just get on with it!! ain’t nobody got time for that

iOS Background Fetch?

• API introduced in iOS 7

• Allows apps to fetch data while in background

• Yes, even when device is in standby mode

• Heavily regulated by iOS - hard to predict

Hard to predict…• iOS decides when app should fetch data

• Users device use patterns

• Device connectivity

• Battery level

• Phase of the moon - probably 😇

Why use it?

• Data is available when user runs app!

• Battery life increase in the long run (at least, that’s what Apple claims)

• Overall user experience => happy users

How? Where? What?• Add “UIBackgroundModes” array to Info.plist

a.k.a. “Required background modes”

• Add “fetch” to array key a.k.a. “App downloads content from the network”

What about the code?• Call a method on UIApplication:

setMinimumBackgroundFetchInterval:Best done in AppDelegate: application:didFinishLaunchingWithOptions:

• Pass minimum amount of seconds between fetch calls

• minimum amount is just a pointer, though… it really is unpredictable

Is that it? Then what?• iOS calls a method on our AppDelegate:

application:performFetchWithCompletionHandler:

• method has 30 seconds to fetch data and call completion handler

• method should return meaningful result to iOS

• result influences pattern of future fetch calls

How about debugging?

Just show the code, or do a demo,

or something!Might be easier 😏

code is available on github

https://github.com/goranche/backgroundSync

One more …nah, not going there ☺️

Q & A