4 whats-new-in-ios7-m4-multitasking-slides

108
Jon Flanders @jonanders What’s new in iOS7 Networking and Multi-tasking Tuesday, September 3, 13

description

 

Transcript of 4 whats-new-in-ios7-m4-multitasking-slides

Page 1: 4 whats-new-in-ios7-m4-multitasking-slides

Jon Flanders@jon!anders

What’s new in iOS7Networking and Multi-tasking

Tuesday, September 3, 13

Page 2: 4 whats-new-in-ios7-m4-multitasking-slides

What you will learn...

Tuesday, September 3, 13

Page 3: 4 whats-new-in-ios7-m4-multitasking-slides

What you will learn...

§ All about the new options for multi-tasking and background execution

Tuesday, September 3, 13

Page 4: 4 whats-new-in-ios7-m4-multitasking-slides

Background Tasks

Tuesday, September 3, 13

Page 5: 4 whats-new-in-ios7-m4-multitasking-slides

Background Tasks

§ Ever since iOS4, apps could request extra time to execute after being sent to the background

Tuesday, September 3, 13

Page 6: 4 whats-new-in-ios7-m4-multitasking-slides

Background Tasks

§ Ever since iOS4, apps could request extra time to execute after being sent to the backgroundo 15 minutes of execution time

Tuesday, September 3, 13

Page 7: 4 whats-new-in-ios7-m4-multitasking-slides

Background Tasks

§ Ever since iOS4, apps could request extra time to execute after being sent to the backgroundo 15 minutes of execution time

§ This API remains in iOS7, but you may not need to use it (more on this later)

Tuesday, September 3, 13

Page 8: 4 whats-new-in-ios7-m4-multitasking-slides

Background Tasks

§ Ever since iOS4, apps could request extra time to execute after being sent to the backgroundo 15 minutes of execution time

§ This API remains in iOS7, but you may not need to use it (more on this later)

§ If you do use it, the execution semantics have changed

Tuesday, September 3, 13

Page 9: 4 whats-new-in-ios7-m4-multitasking-slides

Background Tasks

§ Ever since iOS4, apps could request extra time to execute after being sent to the backgroundo 15 minutes of execution time

§ This API remains in iOS7, but you may not need to use it (more on this later)

§ If you do use it, the execution semantics have changedo If user locked screen in iOS6, the background task would keep the phone awake

Tuesday, September 3, 13

Page 10: 4 whats-new-in-ios7-m4-multitasking-slides

Background Tasks

§ Ever since iOS4, apps could request extra time to execute after being sent to the backgroundo 15 minutes of execution time

§ This API remains in iOS7, but you may not need to use it (more on this later)

§ If you do use it, the execution semantics have changedo If user locked screen in iOS6, the background task would keep the phone awakeo iOS7 puts the app to sleep; the app will get a time-slice once the phone wakes up

Tuesday, September 3, 13

Page 11: 4 whats-new-in-ios7-m4-multitasking-slides

Background Tasks

§ Ever since iOS4, apps could request extra time to execute after being sent to the backgroundo 15 minutes of execution time

§ This API remains in iOS7, but you may not need to use it (more on this later)

§ If you do use it, the execution semantics have changedo If user locked screen in iOS6, the background task would keep the phone awakeo iOS7 puts the app to sleep; the app will get a time-slice once the phone wakes upo Execution time not guaranteed to be contiguous

Tuesday, September 3, 13

Page 12: 4 whats-new-in-ios7-m4-multitasking-slides

New App Switcher

Tuesday, September 3, 13

Page 13: 4 whats-new-in-ios7-m4-multitasking-slides

New App Switcher

§ One of the major changes in the OS

Tuesday, September 3, 13

Page 14: 4 whats-new-in-ios7-m4-multitasking-slides

New App Switcher

§ One of the major changes in the OS§ User can swipe up on app snapshot to kill the app

Tuesday, September 3, 13

Page 15: 4 whats-new-in-ios7-m4-multitasking-slides

New App Switcher

§ One of the major changes in the OS§ User can swipe up on app snapshot to kill the app

o Unlike in iOS6, this also kills background execution

Tuesday, September 3, 13

Page 16: 4 whats-new-in-ios7-m4-multitasking-slides

New APIs

Tuesday, September 3, 13

Page 17: 4 whats-new-in-ios7-m4-multitasking-slides

New APIs

§ Background Fetch

Tuesday, September 3, 13

Page 18: 4 whats-new-in-ios7-m4-multitasking-slides

New APIs

§ Background Fetch§ Remote Noti!cations

Tuesday, September 3, 13

Page 19: 4 whats-new-in-ios7-m4-multitasking-slides

New APIs

§ Background Fetch§ Remote Noti!cations§ Background Transfer Service

Tuesday, September 3, 13

Page 20: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch

Tuesday, September 3, 13

Page 21: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch

§ When an app opens, typically it shows fresh data

Tuesday, September 3, 13

Page 22: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch

§ When an app opens, typically it shows fresh data§ When an app is brought to the foreground after being in the background,

generally the !rst thing most apps do is refresh their data

Tuesday, September 3, 13

Page 23: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch

§ When an app opens, typically it shows fresh data§ When an app is brought to the foreground after being in the background,

generally the !rst thing most apps do is refresh their data o But update happens after the user is already in the app, so the user sees a transition

Tuesday, September 3, 13

Page 24: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch

§ When an app opens, typically it shows fresh data§ When an app is brought to the foreground after being in the background,

generally the !rst thing most apps do is refresh their data o But update happens after the user is already in the app, so the user sees a transition

§ Background Fetch enables an app to update its data in the background

Tuesday, September 3, 13

Page 25: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch

§ When an app opens, typically it shows fresh data§ When an app is brought to the foreground after being in the background,

generally the !rst thing most apps do is refresh their data o But update happens after the user is already in the app, so the user sees a transition

§ Background Fetch enables an app to update its data in the backgroundo If an app is in the background, it will be assigned a time-slice

Tuesday, September 3, 13

Page 26: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch

§ When an app opens, typically it shows fresh data§ When an app is brought to the foreground after being in the background,

generally the !rst thing most apps do is refresh their data o But update happens after the user is already in the app, so the user sees a transition

§ Background Fetch enables an app to update its data in the backgroundo If an app is in the background, it will be assigned a time-sliceo If an app isn’t running, it will be started in the background and then assigned a time-

slice

Tuesday, September 3, 13

Page 27: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch

§ When an app opens, typically it shows fresh data§ When an app is brought to the foreground after being in the background,

generally the !rst thing most apps do is refresh their data o But update happens after the user is already in the app, so the user sees a transition

§ Background Fetch enables an app to update its data in the backgroundo If an app is in the background, it will be assigned a time-sliceo If an app isn’t running, it will be started in the background and then assigned a time-

slice o When and how often the app is assigned a time-slice is controlled by the OS

Tuesday, September 3, 13

Page 28: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

Tuesday, September 3, 13

Page 29: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”

Tuesday, September 3, 13

Page 30: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

Tuesday, September 3, 13

Page 31: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

§ Set the background fetch interval range on your Application object

Tuesday, September 3, 13

Page 32: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

§ Set the background fetch interval range on your Application objecto No repeating interval

Tuesday, September 3, 13

Page 33: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

§ Set the background fetch interval range on your Application objecto No repeating intervalo Time-slice assignment is managed by the OS, the range is set by the developer

Tuesday, September 3, 13

Page 34: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

§ Set the background fetch interval range on your Application objecto No repeating intervalo Time-slice assignment is managed by the OS, the range is set by the developer

§ New delegate callback

Tuesday, September 3, 13

Page 35: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

§ Set the background fetch interval range on your Application objecto No repeating intervalo Time-slice assignment is managed by the OS, the range is set by the developer

§ New delegate callbacko performFetchWithCompletionHandler

Tuesday, September 3, 13

Page 36: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

§ Set the background fetch interval range on your Application objecto No repeating intervalo Time-slice assignment is managed by the OS, the range is set by the developer

§ New delegate callbacko performFetchWithCompletionHandlero Do your work: call the completion handler when you are done

Tuesday, September 3, 13

Page 37: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

§ Set the background fetch interval range on your Application objecto No repeating intervalo Time-slice assignment is managed by the OS, the range is set by the developer

§ New delegate callbacko performFetchWithCompletionHandlero Do your work: call the completion handler when you are doneo After the completion handler is called, if you have new data, it will create a new

snapshot of your app

Tuesday, September 3, 13

Page 38: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

§ Set the background fetch interval range on your Application objecto No repeating intervalo Time-slice assignment is managed by the OS, the range is set by the developer

§ New delegate callbacko performFetchWithCompletionHandlero Do your work: call the completion handler when you are doneo After the completion handler is called, if you have new data, it will create a new

snapshot of your app

§ Update UI for App Switcher

Tuesday, September 3, 13

Page 39: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

§ Set the background fetch interval range on your Application objecto No repeating intervalo Time-slice assignment is managed by the OS, the range is set by the developer

§ New delegate callbacko performFetchWithCompletionHandlero Do your work: call the completion handler when you are doneo After the completion handler is called, if you have new data, it will create a new

snapshot of your app

§ Update UI for App Switcher§ You can test this via debug properties

Tuesday, September 3, 13

Page 40: 4 whats-new-in-ios7-m4-multitasking-slides

Background Fetch API

§ Set the UIBackgroundModes value in the Info.plist to “fetch”o This can also be set this via the new Capabilities page in Xcode

§ Set the background fetch interval range on your Application objecto No repeating intervalo Time-slice assignment is managed by the OS, the range is set by the developer

§ New delegate callbacko performFetchWithCompletionHandlero Do your work: call the completion handler when you are doneo After the completion handler is called, if you have new data, it will create a new

snapshot of your app

§ Update UI for App Switcher§ You can test this via debug properties

o Also on Debug menu

Tuesday, September 3, 13

Page 41: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

Tuesday, September 3, 13

Page 42: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

Tuesday, September 3, 13

Page 43: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

§ Often sent to notify user of new data

Tuesday, September 3, 13

Page 44: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

§ Often sent to notify user of new datao User is noti!ed via alert or popup

Tuesday, September 3, 13

Page 45: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

§ Often sent to notify user of new datao User is noti!ed via alert or popup o If the user clicked on UI, the app was either brought to foreground or started

Tuesday, September 3, 13

Page 46: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

§ Often sent to notify user of new datao User is noti!ed via alert or popup o If the user clicked on UI, the app was either brought to foreground or startedo Race condition: what if app can’t show new data yet because new data can’t even

start to be retrieved until app is in the foreground

Tuesday, September 3, 13

Page 47: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

§ Often sent to notify user of new datao User is noti!ed via alert or popup o If the user clicked on UI, the app was either brought to foreground or startedo Race condition: what if app can’t show new data yet because new data can’t even

start to be retrieved until app is in the foreground

§ iOS7 enables you to send a noti!cation with a new "ag

Tuesday, September 3, 13

Page 48: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

§ Often sent to notify user of new datao User is noti!ed via alert or popup o If the user clicked on UI, the app was either brought to foreground or startedo Race condition: what if app can’t show new data yet because new data can’t even

start to be retrieved until app is in the foreground

§ iOS7 enables you to send a noti!cation with a new "ago content-available : 1

Tuesday, September 3, 13

Page 49: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

§ Often sent to notify user of new datao User is noti!ed via alert or popup o If the user clicked on UI, the app was either brought to foreground or startedo Race condition: what if app can’t show new data yet because new data can’t even

start to be retrieved until app is in the foreground

§ iOS7 enables you to send a noti!cation with a new "ago content-available : 1o When set, the app gets executed before the user gets the noti!cation

Tuesday, September 3, 13

Page 50: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

§ Often sent to notify user of new datao User is noti!ed via alert or popup o If the user clicked on UI, the app was either brought to foreground or startedo Race condition: what if app can’t show new data yet because new data can’t even

start to be retrieved until app is in the foreground

§ iOS7 enables you to send a noti!cation with a new "ago content-available : 1o When set, the app gets executed before the user gets the noti!cationo Hopefully you can get that new data before the user clicks the alert to bring the app

to the foreground

Tuesday, September 3, 13

Page 51: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

§ Often sent to notify user of new datao User is noti!ed via alert or popup o If the user clicked on UI, the app was either brought to foreground or startedo Race condition: what if app can’t show new data yet because new data can’t even

start to be retrieved until app is in the foreground

§ iOS7 enables you to send a noti!cation with a new "ago content-available : 1o When set, the app gets executed before the user gets the noti!cationo Hopefully you can get that new data before the user clicks the alert to bring the app

to the foreground

§ Send content-available:1 without an alert in the payload of the noti!cation

Tuesday, September 3, 13

Page 52: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations

§ Since iOS4, noti!cations could be sent through Apple’s Push Noti!cation Service (APNS)

§ Often sent to notify user of new datao User is noti!ed via alert or popup o If the user clicked on UI, the app was either brought to foreground or startedo Race condition: what if app can’t show new data yet because new data can’t even

start to be retrieved until app is in the foreground

§ iOS7 enables you to send a noti!cation with a new "ago content-available : 1o When set, the app gets executed before the user gets the noti!cationo Hopefully you can get that new data before the user clicks the alert to bring the app

to the foreground

§ Send content-available:1 without an alert in the payload of the noti!cation o This becomes a silent noti!cation and is delivered to the app in the background

Tuesday, September 3, 13

Page 53: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations API

Tuesday, September 3, 13

Page 54: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations API

§ Set UIBackgroundModes to remote-noti!cation in Info.plist

Tuesday, September 3, 13

Page 55: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations API

§ Set UIBackgroundModes to remote-noti!cation in Info.plist o Or use new Capabilities UI in Xcode

Tuesday, September 3, 13

Page 56: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations API

§ Set UIBackgroundModes to remote-noti!cation in Info.plist o Or use new Capabilities UI in Xcode

§ Make sure to set content-available: 1 in the payload

Tuesday, September 3, 13

Page 57: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations API

§ Set UIBackgroundModes to remote-noti!cation in Info.plist o Or use new Capabilities UI in Xcode

§ Make sure to set content-available: 1 in the payload§ The application:didReceiveRemoteNoti!cation:fetchCompletionHandler

is called with a non-null completion handler

Tuesday, September 3, 13

Page 58: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations API

§ Set UIBackgroundModes to remote-noti!cation in Info.plist o Or use new Capabilities UI in Xcode

§ Make sure to set content-available: 1 in the payload§ The application:didReceiveRemoteNoti!cation:fetchCompletionHandler

is called with a non-null completion handlero Call the completion handler when you are done

Tuesday, September 3, 13

Page 59: 4 whats-new-in-ios7-m4-multitasking-slides

Remote Noti!cations API

§ Set UIBackgroundModes to remote-noti!cation in Info.plist o Or use new Capabilities UI in Xcode

§ Make sure to set content-available: 1 in the payload§ The application:didReceiveRemoteNoti!cation:fetchCompletionHandler

is called with a non-null completion handlero Call the completion handler when you are doneo Silent noti!cations will be rate-limited. APNS does the work to make sure that device

isn’t overloaded – delayed but not rejected

Tuesday, September 3, 13

Page 60: 4 whats-new-in-ios7-m4-multitasking-slides

Networking in the Background

Tuesday, September 3, 13

Page 61: 4 whats-new-in-ios7-m4-multitasking-slides

Networking in the Background

§ Before iOS7, you might want to download or upload a resource after the your app has gone to the background

Tuesday, September 3, 13

Page 62: 4 whats-new-in-ios7-m4-multitasking-slides

Networking in the Background

§ Before iOS7, you might want to download or upload a resource after the your app has gone to the background

§ Background Task API would give you a set time-slice

Tuesday, September 3, 13

Page 63: 4 whats-new-in-ios7-m4-multitasking-slides

Networking in the Background

§ Before iOS7, you might want to download or upload a resource after the your app has gone to the background

§ Background Task API would give you a set time-sliceo What if your operation took longer than the time allowed (i.e. a large resource like a

video or image)?

Tuesday, September 3, 13

Page 64: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

Tuesday, September 3, 13

Page 65: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

§ iOS7 introduces the BTS

Tuesday, September 3, 13

Page 66: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

§ iOS7 introduces the BTS§ You can offload network work to the BTS

Tuesday, September 3, 13

Page 67: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

§ iOS7 introduces the BTS§ You can offload network work to the BTS§ BTS will ensure that the work gets completed

Tuesday, September 3, 13

Page 68: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

§ iOS7 introduces the BTS§ You can offload network work to the BTS§ BTS will ensure that the work gets completed

o Works even if your app is in the background or even if it is terminated

Tuesday, September 3, 13

Page 69: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

§ iOS7 introduces the BTS§ You can offload network work to the BTS§ BTS will ensure that the work gets completed

o Works even if your app is in the background or even if it is terminated o If your app wakes up due to background fetch or noti!cation, this is a great API to pair

with it

Tuesday, September 3, 13

Page 70: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

§ iOS7 introduces the BTS§ You can offload network work to the BTS§ BTS will ensure that the work gets completed

o Works even if your app is in the background or even if it is terminated o If your app wakes up due to background fetch or noti!cation, this is a great API to pair

with it

§ BTS manages battery life and data

Tuesday, September 3, 13

Page 71: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

§ iOS7 introduces the BTS§ You can offload network work to the BTS§ BTS will ensure that the work gets completed

o Works even if your app is in the background or even if it is terminated o If your app wakes up due to background fetch or noti!cation, this is a great API to pair

with it

§ BTS manages battery life and data o Requests are classi!ed as discretionary or non-discretionary

Tuesday, September 3, 13

Page 72: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

§ iOS7 introduces the BTS§ You can offload network work to the BTS§ BTS will ensure that the work gets completed

o Works even if your app is in the background or even if it is terminated o If your app wakes up due to background fetch or noti!cation, this is a great API to pair

with it

§ BTS manages battery life and data o Requests are classi!ed as discretionary or non-discretionaryo Discretionary requests will only happen when on WI-FI

Tuesday, September 3, 13

Page 73: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

§ iOS7 introduces the BTS§ You can offload network work to the BTS§ BTS will ensure that the work gets completed

o Works even if your app is in the background or even if it is terminated o If your app wakes up due to background fetch or noti!cation, this is a great API to pair

with it

§ BTS manages battery life and data o Requests are classi!ed as discretionary or non-discretionaryo Discretionary requests will only happen when on WI-FIo Requests from the background are automatically discretionary

Tuesday, September 3, 13

Page 74: 4 whats-new-in-ios7-m4-multitasking-slides

Background Transfer Service (BTS)

§ iOS7 introduces the BTS§ You can offload network work to the BTS§ BTS will ensure that the work gets completed

o Works even if your app is in the background or even if it is terminated o If your app wakes up due to background fetch or noti!cation, this is a great API to pair

with it

§ BTS manages battery life and data o Requests are classi!ed as discretionary or non-discretionaryo Discretionary requests will only happen when on WI-FIo Requests from the background are automatically discretionaryo Requests from the foreground can request to be discretionary

Tuesday, September 3, 13

Page 75: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession

Tuesday, September 3, 13

Page 76: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession

§ New object in iOS7

Tuesday, September 3, 13

Page 77: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession

§ New object in iOS7§ Subsumes the functionality of NSURLConnection

Tuesday, September 3, 13

Page 78: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession

§ New object in iOS7§ Subsumes the functionality of NSURLConnection

o API is similar to NSURLConnection

Tuesday, September 3, 13

Page 79: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession

§ New object in iOS7§ Subsumes the functionality of NSURLConnection

o API is similar to NSURLConnection

§ Adds more functionality than NSURLConnection

Tuesday, September 3, 13

Page 80: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession

§ New object in iOS7§ Subsumes the functionality of NSURLConnection

o API is similar to NSURLConnection

§ Adds more functionality than NSURLConnectiono Instance storage of credentials, cookies, and other state (vs. NSURLConnection’s global

shared state).

Tuesday, September 3, 13

Page 81: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession

§ New object in iOS7§ Subsumes the functionality of NSURLConnection

o API is similar to NSURLConnection

§ Adds more functionality than NSURLConnectiono Instance storage of credentials, cookies, and other state (vs. NSURLConnection’s global

shared state).

§ If your app goes to the background or even is terminated after you make a NSURLSession request, BTS service will still complete the request

Tuesday, September 3, 13

Page 82: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession

§ New object in iOS7§ Subsumes the functionality of NSURLConnection

o API is similar to NSURLConnection

§ Adds more functionality than NSURLConnectiono Instance storage of credentials, cookies, and other state (vs. NSURLConnection’s global

shared state).

§ If your app goes to the background or even is terminated after you make a NSURLSession request, BTS service will still complete the requesto Your app is started or woken up when request is !nished and you have a chance to

process

Tuesday, September 3, 13

Page 83: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

Tuesday, September 3, 13

Page 84: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration object

Tuesday, September 3, 13

Page 85: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.

Tuesday, September 3, 13

Page 86: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.o Background con!guration gets an identi!er (string) to use later to retrieve from BTS

Tuesday, September 3, 13

Page 87: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.o Background con!guration gets an identi!er (string) to use later to retrieve from BTS

§ Implement to appropriate protocols

Tuesday, September 3, 13

Page 88: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.o Background con!guration gets an identi!er (string) to use later to retrieve from BTS

§ Implement to appropriate protocolso NSURLSessionDelegate for high-level events

Tuesday, September 3, 13

Page 89: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.o Background con!guration gets an identi!er (string) to use later to retrieve from BTS

§ Implement to appropriate protocolso NSURLSessionDelegate for high-level eventso NSURLSessionTaskDelegate for data-level events

Tuesday, September 3, 13

Page 90: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.o Background con!guration gets an identi!er (string) to use later to retrieve from BTS

§ Implement to appropriate protocolso NSURLSessionDelegate for high-level eventso NSURLSessionTaskDelegate for data-level events

§ NSURLSessionTask really replaces NSURLConnection

Tuesday, September 3, 13

Page 91: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.o Background con!guration gets an identi!er (string) to use later to retrieve from BTS

§ Implement to appropriate protocolso NSURLSessionDelegate for high-level eventso NSURLSessionTaskDelegate for data-level events

§ NSURLSessionTask really replaces NSURLConnectiono [resume] method to start task

Tuesday, September 3, 13

Page 92: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.o Background con!guration gets an identi!er (string) to use later to retrieve from BTS

§ Implement to appropriate protocolso NSURLSessionDelegate for high-level eventso NSURLSessionTaskDelegate for data-level events

§ NSURLSessionTask really replaces NSURLConnectiono [resume] method to start tasko [cancel],[suspend],[resume] control methods

Tuesday, September 3, 13

Page 93: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.o Background con!guration gets an identi!er (string) to use later to retrieve from BTS

§ Implement to appropriate protocolso NSURLSessionDelegate for high-level eventso NSURLSessionTaskDelegate for data-level events

§ NSURLSessionTask really replaces NSURLConnectiono [resume] method to start tasko [cancel],[suspend],[resume] control methodso Multiple sub-classes for different functions

Tuesday, September 3, 13

Page 94: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.o Background con!guration gets an identi!er (string) to use later to retrieve from BTS

§ Implement to appropriate protocolso NSURLSessionDelegate for high-level eventso NSURLSessionTaskDelegate for data-level events

§ NSURLSessionTask really replaces NSURLConnectiono [resume] method to start tasko [cancel],[suspend],[resume] control methodso Multiple sub-classes for different functions

§ NSURLSession also has block-based convenience methods as well

Tuesday, September 3, 13

Page 95: 4 whats-new-in-ios7-m4-multitasking-slides

NSURLSession API

§ To create an NSURLSession, you need an NSURLSessionCon!guration objecto Con!guration object determines foreground/background execution, whether the

request will use only wi-!, etc.o Background con!guration gets an identi!er (string) to use later to retrieve from BTS

§ Implement to appropriate protocolso NSURLSessionDelegate for high-level eventso NSURLSessionTaskDelegate for data-level events

§ NSURLSessionTask really replaces NSURLConnectiono [resume] method to start tasko [cancel],[suspend],[resume] control methodso Multiple sub-classes for different functions

§ NSURLSession also has block-based convenience methods as wello Still need to call [resume] on task to kick off connection

Tuesday, September 3, 13

Page 96: 4 whats-new-in-ios7-m4-multitasking-slides

Background Considerations

Tuesday, September 3, 13

Page 97: 4 whats-new-in-ios7-m4-multitasking-slides

Background Considerations

§ Limited time

Tuesday, September 3, 13

Page 98: 4 whats-new-in-ios7-m4-multitasking-slides

Background Considerations

§ Limited timeo You still only get a limited time to execute in the background (less than 1 minute)

Tuesday, September 3, 13

Page 99: 4 whats-new-in-ios7-m4-multitasking-slides

Background Considerations

§ Limited timeo You still only get a limited time to execute in the background (less than 1 minute)o Make sure to call the completion handlers ALWAYS in less than 1 minute

Tuesday, September 3, 13

Page 100: 4 whats-new-in-ios7-m4-multitasking-slides

Background Considerations

§ Limited timeo You still only get a limited time to execute in the background (less than 1 minute)o Make sure to call the completion handlers ALWAYS in less than 1 minuteo Use BTS to enhance the work you can do when called in the background

Tuesday, September 3, 13

Page 101: 4 whats-new-in-ios7-m4-multitasking-slides

Background Considerations

§ Limited timeo You still only get a limited time to execute in the background (less than 1 minute)o Make sure to call the completion handlers ALWAYS in less than 1 minuteo Use BTS to enhance the work you can do when called in the background

§ User control

Tuesday, September 3, 13

Page 102: 4 whats-new-in-ios7-m4-multitasking-slides

Background Considerations

§ Limited timeo You still only get a limited time to execute in the background (less than 1 minute)o Make sure to call the completion handlers ALWAYS in less than 1 minuteo Use BTS to enhance the work you can do when called in the background

§ User controlo User can turn off or limit background fetch

Tuesday, September 3, 13

Page 103: 4 whats-new-in-ios7-m4-multitasking-slides

Background Considerations

§ Limited timeo You still only get a limited time to execute in the background (less than 1 minute)o Make sure to call the completion handlers ALWAYS in less than 1 minuteo Use BTS to enhance the work you can do when called in the background

§ User controlo User can turn off or limit background fetch

§ Data Protection

Tuesday, September 3, 13

Page 104: 4 whats-new-in-ios7-m4-multitasking-slides

Background Considerations

§ Limited timeo You still only get a limited time to execute in the background (less than 1 minute)o Make sure to call the completion handlers ALWAYS in less than 1 minuteo Use BTS to enhance the work you can do when called in the background

§ User controlo User can turn off or limit background fetch

§ Data Protectiono If you use the recommended levels of data protection, you won’t be able to access !les, keychain, or sqlite DBs when running in the background

Tuesday, September 3, 13

Page 105: 4 whats-new-in-ios7-m4-multitasking-slides

Background Considerations

§ Limited timeo You still only get a limited time to execute in the background (less than 1 minute)o Make sure to call the completion handlers ALWAYS in less than 1 minuteo Use BTS to enhance the work you can do when called in the background

§ User controlo User can turn off or limit background fetch

§ Data Protectiono If you use the recommended levels of data protection, you won’t be able to access !les, keychain, or sqlite DBs when running in the background

o If you need credentials in the background, to lower risk, consider a token that expires in a short amount of time

Tuesday, September 3, 13

Page 106: 4 whats-new-in-ios7-m4-multitasking-slides

Summary

Tuesday, September 3, 13

Page 107: 4 whats-new-in-ios7-m4-multitasking-slides

Summary

§ The new background execution features help your app seem to the user to be running all the time

Tuesday, September 3, 13

Page 108: 4 whats-new-in-ios7-m4-multitasking-slides

Summary

§ The new background execution features help your app seem to the user to be running all the time

§ The new NSURLSession and BTS make foreground networking code simpler and background networking code possible

Tuesday, September 3, 13