SlideShare a Scribd company logo
Multitasking in iOS 7
Mickaël Rémond <mremond@boxcar.io>

Universal Push Notification Platform
Pre-iOS 7 options for background modes
Previously you had access to the following options:
!

Audio playback
Location update
Task completion (up to 10 minutes)
Newsstand download
Voice-over-IP (VoIP) services
Accessory or CoreBluetooth communication
!

Specific limitations for each of them

Universal Push Notification Platform
Change in background tasks handling (1/3)
Apps will get scheduled when device is active and
not keep it awake
They still get up to 10 minutes run time, not
guaranteed to be continuous
!

WWDC 204

Universal Push Notification Platform
Change in background tasks handling (2/3)
// AppDelegate
UIBackgroundTaskIdentifier background_task;

!

- (void)applicationDidEnterBackground:(UIApplication *)application
{
if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
{
NSLog(@"Multitasking Supported");
if (background_task == UIBackgroundTaskInvalid) {
background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
NSLog(@"Background task expirationn");
//Clean up code. Tell the system that we are done.
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
}];
//To make the code block asynchronous
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//### background task starts
NSLog(@"Running in the backgroundn");
while(TRUE)
{
NSLog(@"Background time Remaining: %f",[[UIApplication sharedApplication] backgroundTimeRemaining]);
[NSThread sleepForTimeInterval:1]; //wait for 1 sec
}
//#### background task ends
//Clean up code. Tell the system that we are done.
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
});
}
else
{
NSLog(@"Multitasking Not Supported");
}
}
}

!

Universal Push Notification Platform
Change in background tasks handling (3/3)
On iOS 6, starts with 10 min:
2013-11-14 08:59:54.165 Background1[149:1103] Background time Remaining: 599.981943

!
!

On iOS 7, starts with 3 min:
2013-11-14 09:02:33.182 Background1[6315:1803] Background time Remaining: 179.942678

!

This is a big change for many apps using
background tasks.
!

I never seem task being scheduled discontinously …
Yet.

Universal Push Notification Platform
iOS 7 new background modes
With iOS 7 you have three new modes:
!

Background fetching
Remote notification
Background transfers
!

All modes keep Apple and users in control to
preserve battery life

Universal Push Notification Platform
Project *info.plist: select background modes
Two new modes available:
!

fetch (App downloads content from the
network)
remote-notification (App download
content in response to push notifications)

Universal Push Notification Platform
Background fetch

Universal Push Notification Platform
Background fetching: close control
!

iOS stays in control: “Application launched
opportunistically”
Coalesced across applications
means scheduled based on usage pattern
sensitive to energy and data usage
!

Users stay in control:
Force close disable background fetch
Dedicated setting panel

Universal Push Notification Platform
Background fetching: user control
Preferences -> General -> Background App Refresh

Universal Push Notification Platform
Background fetching: usage patterns
WWDC 204

Universal Push Notification Platform
Background fetching: App Delegate
New delegate method on UIApplication is called
- (void)application:(UIApplication *)application!
performFetchWithCompletionHandler:(void (^)
(UIBackgroundFetchResult!
result))completionHandler;!

!

Call the completion handler when fetch is complete
to let iOS 7 learn about data availability patterns:
UIBackgroundFetchResultNewData!
UIBackgroundFetchResultNoData!
UIBackgroundFetchResultFailed

Universal Push Notification Platform
Background fetching: Limit server load
At application launch:
!

Define the minimum fetch interval to limit server load:
- (void)setMinimumBackgroundFetchInterval:
(NSTimeInterval)minInterval;!

!

Use constants:
const NSTimeInterval UIApplicationBackgroundFetchIntervalMinimum!
const NSTimeInterval UIApplicationBackgroundFetchIntervalNever!

!

More likely custom values (in seconds)

Universal Push Notification Platform
Background fetching: Tips
Simulate background fetch for testing
Do not forget simulator has an option to
manually trigger background fetch
Limit operation to bare minimum
You have at most 30 seconds of time to
perform download operation
Use NSURLSession to benefit from background
download infrastructure
Track background fetches per user on your server
to discover patterns

Universal Push Notification Platform
Remote notifications

Universal Push Notification Platform
Remote notifs: Dev and Apple control
Developers control:
content-available set to 1 in APNS
payload to tell the application content is
available.
!

Apple stays in control:
Silent notification (without sound / alert /
badge) can be delayed: Battery saving
Normal notifications are send immediately

Universal Push Notification Platform
Remote notifs: App Delegate
New delegate method on UIApplication is called
- (void)application:(UIApplication *)application!
didReceiveRemoteNotification:(NSDictionary
*)userInfo!
fetchCompletionHandler:(void (^)
(UIBackgroundFetchResult result))completionHandler;!

!

Call the completion handler when download is
complete to let iOS 7 learn about data availability
patterns:
UIBackgroundFetchResultNewData!
UIBackgroundFetchResultNoData!
UIBackgroundFetchResultFailed!

Universal Push Notification Platform
Remote notifs: Tips
!

Limit operation to bare minimum
You have at most 30 seconds of time to
perform download operation
!

Use NSURLSession to benefit from background
download infrastructure

Universal Push Notification Platform
Background transfers

Universal Push Notification Platform
Background transfers: Usage
!

Used for data download and upload
!

Used for granting iOS control over background
operation
!

Does not obsolete AFNetworking especially if you
need parsing / serialization
!

Quite a large piece of code with many options:
Take the time to learn them, they are powerful

Universal Push Notification Platform
Background transfers: Nice features
!

Download / upload tasks in background
!

Discretionary setting to save battery
!

Limit download to Wifi only

Universal Push Notification Platform
Background transfers: Tips
!

Take the time to explore all the options / cases. To
implement complex cases, data will flow through
multiple paths in code
!

Not “magic”: You still have to handle network failure
and errors, resume on the next chunk
Do not forget there is a server on the back that
will timeout at some point
!

Take it as a great toolbox to handle advanced cases

Universal Push Notification Platform
References
Talk example code
https://github.com/boxcar/talk-code-examples/tree/
master/background-ios7
!

Background Modes in iOS Tutorial (pre-iOS 7)
http://www.raywenderlich.com/29948/
backgrounding-for-ios
!

WWDC 2013 Session 204: What’s new with
multitasking.

Universal Push Notification Platform

More Related Content

PDF
What's new in ios 7.0
PDF
Framework dynamic par Simone Sivetta
PDF
Parse par Nicolas Lauquin
PDF
Revue des annonces WWDC2015
PDF
Mastering Interface Builder
PDF
BlaBlaCar et la mise en place d'une fonctionnalité FlagFeature
PPTX
Continuous integration by Rémy Virin
PDF
Accessors Vs Direct access to properties & Design Pattern
What's new in ios 7.0
Framework dynamic par Simone Sivetta
Parse par Nicolas Lauquin
Revue des annonces WWDC2015
Mastering Interface Builder
BlaBlaCar et la mise en place d'une fonctionnalité FlagFeature
Continuous integration by Rémy Virin
Accessors Vs Direct access to properties & Design Pattern

What's hot (20)

PDF
Travis and fastlane
PDF
Lesson 02 - React Native Development Environment Setup
PDF
6 swt programming
PPTX
Appcelerator Titanium Intro
PPSX
Swt vs swing
PDF
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
PDF
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
PPTX
An overview of the Windows Phone 7 platform
PPT
SWT - Technical Deep Dive
PDF
HotPush with Ionic 2 and CodePush
PDF
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
PPTX
Introduction to MonoTouch
PPTX
JavaFX and WidgetFX at SVCodeCamp
PDF
Sync is hard: building offline-first Android apps from the ground up
PDF
Android App development and test environment, Understaing android app structure
PDF
UIViewControllerのコーナーケース
PPTX
[Devoxx Morocco 2015] Apache Cordova In Action
PPTX
Titanium Appcelerator - Beginners
PPTX
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
KEY
Titanium appcelerator best practices
Travis and fastlane
Lesson 02 - React Native Development Environment Setup
6 swt programming
Appcelerator Titanium Intro
Swt vs swing
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
An overview of the Windows Phone 7 platform
SWT - Technical Deep Dive
HotPush with Ionic 2 and CodePush
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Introduction to MonoTouch
JavaFX and WidgetFX at SVCodeCamp
Sync is hard: building offline-first Android apps from the ground up
Android App development and test environment, Understaing android app structure
UIViewControllerのコーナーケース
[Devoxx Morocco 2015] Apache Cordova In Action
Titanium Appcelerator - Beginners
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
Titanium appcelerator best practices
Ad

Viewers also liked (20)

KEY
iOS Backgrounding - SLC Cocoaheads
ZIP
WaveOne server and client by ProcessOne
PDF
Multi Chat
PDF
Erlang White Label
PDF
2015: L'année d'Elixir, Code, écosystème et communauté
ZIP
Real time Web Application with XMPP and Wave
PDF
Event Driven Architecture Concepts in Web Technologies - Part 2
PDF
Create Your Own Language
PDF
Nanomsg - Scalable Networking Library
PDF
Archipel Introduction - ejabberd SF Meetup
ZIP
OneTeam Media Server
ZIP
ProcessOne Push Platform: XMPP-based Push Solutions
PDF
Real life XMPP Instant Messaging
PDF
Nodejs Applications in Production
PDF
XMPP Academy #1
PDF
Event Driven Architecture Concepts in Web Technologies - Part 1
PDF
Practical Look at Erlang
PDF
A vision for ejabberd - ejabberd SF Meetup
PDF
Phoenix Presence: Le service temps réel de Phoenix - Paris.ex #8
KEY
The Real Time Web with XMPP
iOS Backgrounding - SLC Cocoaheads
WaveOne server and client by ProcessOne
Multi Chat
Erlang White Label
2015: L'année d'Elixir, Code, écosystème et communauté
Real time Web Application with XMPP and Wave
Event Driven Architecture Concepts in Web Technologies - Part 2
Create Your Own Language
Nanomsg - Scalable Networking Library
Archipel Introduction - ejabberd SF Meetup
OneTeam Media Server
ProcessOne Push Platform: XMPP-based Push Solutions
Real life XMPP Instant Messaging
Nodejs Applications in Production
XMPP Academy #1
Event Driven Architecture Concepts in Web Technologies - Part 1
Practical Look at Erlang
A vision for ejabberd - ejabberd SF Meetup
Phoenix Presence: Le service temps réel de Phoenix - Paris.ex #8
The Real Time Web with XMPP
Ad

Similar to Multitasking in iOS 7 (20)

PDF
Background Fetch - the most powerful API you've never heard of
KEY
iOS4 multitasking development notes
PDF
4 whats-new-in-ios7-m4-multitasking-slides
ODP
I os meetup_1019
KEY
Local Notifications @ Melbourne Cocoaheads (Aug 10)
PDF
Get step-by-step instructions on implementing notifications in your apps.
PDF
Petr Dvořák: Push notifikace ve velkém
PPTX
Apple notification push
PDF
Особенности фоновой работы iOS-приложения на примере синхронизации Яндекс.Ди...
PDF
In the hunt of 100% delivery rate with mobile push notifications
PDF
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
PDF
Improving apps with iOS 10 notifications (do iOS 2016)
PPTX
A look behind the scenes: Windows 8 background processing
PDF
Mobile Push Notifications
PDF
iOS: A Broad Overview
PDF
Lime - Push notifications. The big way.
PDF
Iphone app programming guide
PPTX
Brug - Web push notification
PPTX
push_notification
PDF
Leveraging Zend Framework for Sending Push Notifications
Background Fetch - the most powerful API you've never heard of
iOS4 multitasking development notes
4 whats-new-in-ios7-m4-multitasking-slides
I os meetup_1019
Local Notifications @ Melbourne Cocoaheads (Aug 10)
Get step-by-step instructions on implementing notifications in your apps.
Petr Dvořák: Push notifikace ve velkém
Apple notification push
Особенности фоновой работы iOS-приложения на примере синхронизации Яндекс.Ди...
In the hunt of 100% delivery rate with mobile push notifications
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
Improving apps with iOS 10 notifications (do iOS 2016)
A look behind the scenes: Windows 8 background processing
Mobile Push Notifications
iOS: A Broad Overview
Lime - Push notifications. The big way.
Iphone app programming guide
Brug - Web push notification
push_notification
Leveraging Zend Framework for Sending Push Notifications

More from Mickaël Rémond (11)

PDF
Go for Real Time Streaming Architectures - DotGo 2017
PDF
Fighting XMPP abuse and spam with ejabberd - ejabberd Workshop #1
PDF
Managing ejabberd Platforms with Docker - ejabberd Workshop #1
PDF
Messaging temps réel avec Go
PDF
Building Scalable Systems: What you can learn from Erlang - DotScale 2016
PPTX
Property-based testing of XMPP: generate your tests automatically - ejabberd ...
PDF
IoT Studio #1: Protocols introduction and connected jukebox
PDF
Deep Dive Into ejabberd Pubsub Implementation
PDF
XMPP Academy #3
PPTX
XMPP Academy #2
ZIP
OneTeam Media Server
Go for Real Time Streaming Architectures - DotGo 2017
Fighting XMPP abuse and spam with ejabberd - ejabberd Workshop #1
Managing ejabberd Platforms with Docker - ejabberd Workshop #1
Messaging temps réel avec Go
Building Scalable Systems: What you can learn from Erlang - DotScale 2016
Property-based testing of XMPP: generate your tests automatically - ejabberd ...
IoT Studio #1: Protocols introduction and connected jukebox
Deep Dive Into ejabberd Pubsub Implementation
XMPP Academy #3
XMPP Academy #2
OneTeam Media Server

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Big Data Technologies - Introduction.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Unlocking AI with Model Context Protocol (MCP)
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
Reach Out and Touch Someone: Haptics and Empathic Computing
The AUB Centre for AI in Media Proposal.docx
“AI and Expert System Decision Support & Business Intelligence Systems”
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
sap open course for s4hana steps from ECC to s4
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
cuic standard and advanced reporting.pdf

Multitasking in iOS 7

  • 1. Multitasking in iOS 7 Mickaël Rémond <mremond@boxcar.io> Universal Push Notification Platform
  • 2. Pre-iOS 7 options for background modes Previously you had access to the following options: ! Audio playback Location update Task completion (up to 10 minutes) Newsstand download Voice-over-IP (VoIP) services Accessory or CoreBluetooth communication ! Specific limitations for each of them Universal Push Notification Platform
  • 3. Change in background tasks handling (1/3) Apps will get scheduled when device is active and not keep it awake They still get up to 10 minutes run time, not guaranteed to be continuous ! WWDC 204 Universal Push Notification Platform
  • 4. Change in background tasks handling (2/3) // AppDelegate UIBackgroundTaskIdentifier background_task; ! - (void)applicationDidEnterBackground:(UIApplication *)application { if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) { NSLog(@"Multitasking Supported"); if (background_task == UIBackgroundTaskInvalid) { background_task = [application beginBackgroundTaskWithExpirationHandler:^ { NSLog(@"Background task expirationn"); //Clean up code. Tell the system that we are done. [application endBackgroundTask: background_task]; background_task = UIBackgroundTaskInvalid; }]; //To make the code block asynchronous dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //### background task starts NSLog(@"Running in the backgroundn"); while(TRUE) { NSLog(@"Background time Remaining: %f",[[UIApplication sharedApplication] backgroundTimeRemaining]); [NSThread sleepForTimeInterval:1]; //wait for 1 sec } //#### background task ends //Clean up code. Tell the system that we are done. [application endBackgroundTask: background_task]; background_task = UIBackgroundTaskInvalid; }); } else { NSLog(@"Multitasking Not Supported"); } } } ! Universal Push Notification Platform
  • 5. Change in background tasks handling (3/3) On iOS 6, starts with 10 min: 2013-11-14 08:59:54.165 Background1[149:1103] Background time Remaining: 599.981943 ! ! On iOS 7, starts with 3 min: 2013-11-14 09:02:33.182 Background1[6315:1803] Background time Remaining: 179.942678 ! This is a big change for many apps using background tasks. ! I never seem task being scheduled discontinously … Yet. Universal Push Notification Platform
  • 6. iOS 7 new background modes With iOS 7 you have three new modes: ! Background fetching Remote notification Background transfers ! All modes keep Apple and users in control to preserve battery life Universal Push Notification Platform
  • 7. Project *info.plist: select background modes Two new modes available: ! fetch (App downloads content from the network) remote-notification (App download content in response to push notifications) Universal Push Notification Platform
  • 8. Background fetch Universal Push Notification Platform
  • 9. Background fetching: close control ! iOS stays in control: “Application launched opportunistically” Coalesced across applications means scheduled based on usage pattern sensitive to energy and data usage ! Users stay in control: Force close disable background fetch Dedicated setting panel Universal Push Notification Platform
  • 10. Background fetching: user control Preferences -> General -> Background App Refresh Universal Push Notification Platform
  • 11. Background fetching: usage patterns WWDC 204 Universal Push Notification Platform
  • 12. Background fetching: App Delegate New delegate method on UIApplication is called - (void)application:(UIApplication *)application! performFetchWithCompletionHandler:(void (^) (UIBackgroundFetchResult! result))completionHandler;! ! Call the completion handler when fetch is complete to let iOS 7 learn about data availability patterns: UIBackgroundFetchResultNewData! UIBackgroundFetchResultNoData! UIBackgroundFetchResultFailed Universal Push Notification Platform
  • 13. Background fetching: Limit server load At application launch: ! Define the minimum fetch interval to limit server load: - (void)setMinimumBackgroundFetchInterval: (NSTimeInterval)minInterval;! ! Use constants: const NSTimeInterval UIApplicationBackgroundFetchIntervalMinimum! const NSTimeInterval UIApplicationBackgroundFetchIntervalNever! ! More likely custom values (in seconds) Universal Push Notification Platform
  • 14. Background fetching: Tips Simulate background fetch for testing Do not forget simulator has an option to manually trigger background fetch Limit operation to bare minimum You have at most 30 seconds of time to perform download operation Use NSURLSession to benefit from background download infrastructure Track background fetches per user on your server to discover patterns Universal Push Notification Platform
  • 15. Remote notifications Universal Push Notification Platform
  • 16. Remote notifs: Dev and Apple control Developers control: content-available set to 1 in APNS payload to tell the application content is available. ! Apple stays in control: Silent notification (without sound / alert / badge) can be delayed: Battery saving Normal notifications are send immediately Universal Push Notification Platform
  • 17. Remote notifs: App Delegate New delegate method on UIApplication is called - (void)application:(UIApplication *)application! didReceiveRemoteNotification:(NSDictionary *)userInfo! fetchCompletionHandler:(void (^) (UIBackgroundFetchResult result))completionHandler;! ! Call the completion handler when download is complete to let iOS 7 learn about data availability patterns: UIBackgroundFetchResultNewData! UIBackgroundFetchResultNoData! UIBackgroundFetchResultFailed! Universal Push Notification Platform
  • 18. Remote notifs: Tips ! Limit operation to bare minimum You have at most 30 seconds of time to perform download operation ! Use NSURLSession to benefit from background download infrastructure Universal Push Notification Platform
  • 19. Background transfers Universal Push Notification Platform
  • 20. Background transfers: Usage ! Used for data download and upload ! Used for granting iOS control over background operation ! Does not obsolete AFNetworking especially if you need parsing / serialization ! Quite a large piece of code with many options: Take the time to learn them, they are powerful Universal Push Notification Platform
  • 21. Background transfers: Nice features ! Download / upload tasks in background ! Discretionary setting to save battery ! Limit download to Wifi only Universal Push Notification Platform
  • 22. Background transfers: Tips ! Take the time to explore all the options / cases. To implement complex cases, data will flow through multiple paths in code ! Not “magic”: You still have to handle network failure and errors, resume on the next chunk Do not forget there is a server on the back that will timeout at some point ! Take it as a great toolbox to handle advanced cases Universal Push Notification Platform
  • 23. References Talk example code https://github.com/boxcar/talk-code-examples/tree/ master/background-ios7 ! Background Modes in iOS Tutorial (pre-iOS 7) http://www.raywenderlich.com/29948/ backgrounding-for-ios ! WWDC 2013 Session 204: What’s new with multitasking. Universal Push Notification Platform