SlideShare a Scribd company logo
1 of 80
Download to read offline
| The Junction
Sunday, July 31, 2011
Multitasking in iOS
      The Junction




       Ori Goshen
       Co-Founder & Chief Architect
       mail: ori@tawkon.com
       twitter: @origoshen

                        | The Junction   2

Sunday, July 31, 2011
OUTLINE

                        • Introduction
                        • Multitasking In iOS Overview
                        • Application Life Cycle
                        • Best Practices
                        • Multitasking & Development Tools




                          | The Junction                     3

Sunday, July 31, 2011
Introduction




                        | The Junction                  4

Sunday, July 31, 2011
ME

                        • Coder since birth
                        • IDF (8200) - Project manager & dev. team leader
                        • Fring - Product & development team leader
                        • Tawkon - Co-Founder & Chief Architect
                        • Love & hate relationship with 




                          | The Junction                                    5

Sunday, July 31, 2011
ABOUT TAWKON




              Drive Safely               Eat Wisely   Talk Responsibly




                        | The Junction                               6

Sunday, July 31, 2011
ABOUT TAWKON




                        | The Junction   7

Sunday, July 31, 2011
HOW APPLE THINKS?




                        | The Junction   8

Sunday, July 31, 2011
MIND & SPIRIT
                • Watch Apple Engineering Video Tutorials
                • Watch WWDC Technical Sessions & Keynote
                • Read The Guidelines! It’s NOT A Waste Of Time
                  • Read Coding Documentation
                • Follow Apple Evangelists On Twitter
                • Follow @gruber
                • Go to macrumors.com
                • Go to tuaw.com (how I found my iPhone)




                        | The Junction                            9

Sunday, July 31, 2011
Multitasking In iOS Overview




                        | The Junction                        10

Sunday, July 31, 2011
INTRODUCTION
                •       A major feature introduced in iOS 4
                •       Improves user experience
                •       “Every app should adopt multitasking”
                •       Supported on all iOS Devices
                        • Except old ones (iPhone, iPhone 3G, 1st gen. touch)
                • Android vs. iPhone Multitasking
                  • Multitasking Android Campaign




                          | The Junction                                        11

Sunday, July 31, 2011
iOS MULTITASKING PHILOSOPHY
                • “General purpose concurrency is not the solution for
                        mobile devices”


                            Background execution:
                            finish task, audio,
                            location, VoIP


                              Push
                              Notification

                                                            Fast App
                                                            Switching




                          | The Junction                                 12

Sunday, July 31, 2011
THE SERVICES
                        • Fast App Switching
                          • Resume quickly, preserve state
                        • Push Notifications
                          • Respond to a notification sent from a remote server
                        • Local Notifications
                          • Push-style notification delivered at a predetermined time
                        • NewsStand Push Notification (New on iOS 5)




                          | The Junction                                               13

Sunday, July 31, 2011
THE SERVICES
                • Background audio
                  • Play audible content to the user while in the background
                • Task completion
                  • Extra time to complete a task
                • Location-Navigation
                  • Keep users continuously informed of their location
                • Location-Significant location change, region monitoring
                  • Respond to location changes while in the background
                • Voice over IP
                  • Make and receive phone calls using an Internet connection


                        | The Junction                                          14

Sunday, July 31, 2011
| The Junction   15

Sunday, July 31, 2011
DO YOU REALLY NEED TO MULTITASK?




                        | The Junction          16

Sunday, July 31, 2011
WHAT IF... I’M DOING SOMETHING ELSE?
                • Triple check if this is something that can be done remotely
                • Server side push notifications
                • Daemons (Jailbroken Option)

                • Mmmm....What about a clipboard history app?
                • Piggyback on available scenario and think of a damn good
                        excuse (you gonna need it!)




                          | The Junction                                        17

Sunday, July 31, 2011
FAST APP SWITCHING
                        •   App Resumes Immediately
                        •   App State Is Preserved
                        •   Tight integration with multitasking UI
                        •   Default for all apps being developed on SDK 4+
                        •   In other words: “processes are being suspended”




                            | The Junction                                    18

Sunday, July 31, 2011
TASK COMPLETION
                        • Application can complete a task without remaining in
                          the foreground
                        • User does not have to wait for the task to complete
                        • Task duration is limited to avoid excessive battery
                          drain
                        • Examples:
                          • Uploading photos or videos
                          • Finishes applying an image filter
                          • Finishes downloading a magazine




                          | The Junction                                         19

Sunday, July 31, 2011
BACKGROUND AUDIO
                        •   Plays audible content to the user
                        •   Streams audio
                        •   Record audio
                        •   Continue playing/recording in the background
                        •   Integrates with remote controls




                        | The Junction                                     20

Sunday, July 31, 2011
LOCATION NAVIGATION
                        • Keep users informed of their location in the
                          background
                        • Gives turn-by-turn directions




                        | The Junction                                   21

Sunday, July 31, 2011
LOCATION TRACKING
                        • Respond to location changes while in the
                          background
                        • Suitable for location aware apps
                        • Significant location changes
                          • Sends notification after changing cell towers
                        • Region monitoring
                          • Sends a notification upon entering and
                             exiting regions of interest
                          • Not supported on old iPhone (3G, 3GS, ..)




                        | The Junction                                     22

Sunday, July 31, 2011
LOCATION TRACKING
                Significant location changes
                        Significant location changes




                                      Location    Location   Location
                                      changed     changed    changed




                                                                        57




                           | The Junction                                    23

Sunday, July 31, 2011
LOCATION TRACKING
                Region monitoring
                        Region monitoring




                                            Entered
                                             region




                                                      62




                           | The Junction                  24

Sunday, July 31, 2011
VOIP
                • Helps you maintain the connection with the VOIP server
                  • Keep alive with the server (min. of 10 mins.)
                • Maintain a signaling connection
                • Notifying the user on incoming call




                        | The Junction                                     25

Sunday, July 31, 2011
Application Life Cycle




                        | The Junction                            26

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Launch and active/inactive
                                         Foreground

                                                  Active



                                                  Inactive




                                               Not Running



                                         Background

                                                 Running



                                                Suspended




                        | The Junction                       27

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Launch and active/inactive
                                         Foreground

                                                  Active



                                                  Inactive




                                               Not Running



                                         Background

                                                 Running



                                                Suspended




                        | The Junction                       27

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Launch and active/inactive
                                                Foreground

                                                         Active



                                                         Inactive




            applicationDidFinishLaunchingWith
            Options:                                  Not Running



                                                Background

                                                        Running



                                                       Suspended




                        | The Junction                              27

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Launch and active/inactive
                                                Foreground

                                                         Active



                                                         Inactive




            applicationDidFinishLaunchingWith
            Options:                                  Not Running



                                                Background

                                                        Running



                                                       Suspended




                        | The Junction                              27

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Launch and active/inactive
                                                Foreground

                applicationDidBecomeActive:              Active



                                                         Inactive




            applicationDidFinishLaunchingWith
            Options:                                  Not Running



                                                Background

                                                        Running



                                                       Suspended




                         | The Junction                             27

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Launch and active/inactive
                                                Foreground

                applicationDidBecomeActive:              Active



                                                         Inactive




            applicationDidFinishLaunchingWith
            Options:                                  Not Running



                                                Background

                                                        Running



                                                       Suspended




                         | The Junction                             27

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Launch and active/inactive
                                                Foreground

                applicationDidBecomeActive:              Active


                 applicationWillResignActive:
                                                         Inactive




            applicationDidFinishLaunchingWith
            Options:                                  Not Running



                                                Background

                                                        Running



                                                       Suspended




                          | The Junction                            27

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch from an app

                                           Foreground

                                                       Active



                                                       Inactive




                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                            28

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch from an app

                                           Foreground

                                                       Active



                                                       Inactive




                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                            28

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch from an app

                                           Foreground

                                                       Active

                                                                  applicationWillResignActive:

                                                       Inactive




                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                                                           28

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch from an app

                                           Foreground

                                                       Active

                                                                  applicationWillResignActive:

                                                       Inactive




                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                                                           28

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch from an app

                                           Foreground

                                                       Active

                                                                   applicationWillResignActive:

                                                       Inactive



                                                                  applicationDidEnterBackground:
                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                                                             28

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch from an app

                                           Foreground

                                                       Active

                                                                   applicationWillResignActive:

                                                       Inactive



                                                                  applicationDidEnterBackground:
                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                                                             28

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch from an app

                                           Foreground

                                                       Active

                                                                   applicationWillResignActive:

                                                       Inactive



                                                                  applicationDidEnterBackground:
                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                                                             28

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch to an app

                                           Foreground

                                                       Active



                                                       Inactive




                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                            29

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch to an app

                                           Foreground

                                                       Active



                                                       Inactive




                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                            29

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch to an app

                                           Foreground

                                                       Active



                                                       Inactive




                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                            29

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch to an app

                                           Foreground

                                                       Active



                                                       Inactive




                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                            29

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch to an app

                                           Foreground

                                                       Active



                                                       Inactive



                                                                  applicationDidEnterForeground:
                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                                                             29

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch to an app

                                           Foreground

                                                       Active



                                                       Inactive



                                                                  applicationDidEnterForeground:
                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                                                             29

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Switch to an app

                                           Foreground

                                                       Active

                                                                   applicationDidBecomeActive:

                                                       Inactive



                                                                  applicationDidEnterForeground:
                                         Not Running



                                           Background

                                                       Running



                                                   Suspended




                        | The Junction                                                             29

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Termination

                                                 Foreground

                                                          Active



                                                          Inactive




                                         Not Running



                                                 Background

                                                         Running



                                                        Suspended




                        | The Junction                               30

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Termination

                                                 Foreground

                                                          Active



                                                          Inactive




                                         Not Running



                                                 Background

                                                         Running



                                                        Suspended




                        | The Junction                               30

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Termination

                                                  Foreground

                                                           Active



                                                           Inactive




                                          Not Running


           applicationWillTerminate:
                                                  Background

                                                          Running



                                                         Suspended




                         | The Junction                               30

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Termination

                                                  Foreground

                                                           Active



                                                           Inactive




                                          Not Running


           applicationWillTerminate:
                                                  Background

                                                          Running



                                                         Suspended




                         | The Junction                               30

Sunday, July 31, 2011
APPLICATION LIFE CYCLE
                Termination

                                                  Foreground

                                                           Active



                                                           Inactive




                                          Not Running


           applicationWillTerminate:
                                                  Background

                                                          Running



                                                         Suspended




                         | The Junction                               30

Sunday, July 31, 2011
LIFE CYCLE NOTIFICATIONS

                              UIApplicationDelegate Callback                         Notification

                    application:didFinishLaunchingWithOptions:   UIApplicationDidFinishLaunchingNotification

                    applicationWillTerminate:                    UIApplicationWillTerminateNotification

                    applicationDidBecomeActive:                  UIApplicationDidBecomeActiveNotification

                    applicationWillResignActive:                 UIApplicationWillResignActiveNotification

                    applicationDidEnterBackground:               UIApplicationDidEnterBackgroundNotification

                    applicationWillEnterForeground:              UIApplicationWillEnterForegroundNotification




                          | The Junction                                                                       31

Sunday, July 31, 2011
Best Practices




                        | The Junction                    32

Sunday, July 31, 2011
BEST PRACTICES OUTLINE

                        • System Resources
                          • Memory
                          • OpenGL
                        • Gracefully resuming from the background
                          • Preserving state
                          • Networking
                          • System notifications




                          | The Junction                            33

Sunday, July 31, 2011
SYSTEM RESOURCES




                                         17




                        | The Junction        34

Sunday, July 31, 2011
RESOURCE MANAGEMENT
                        • Apps share system resources:
                          • CPU
                          • I/O
                          • Memory
                          • GPU
                          • Network




                          | The Junction                 35

Sunday, July 31, 2011
RESOURCE MANAGEMENT
                        • Goals
                          • Preserve foreground app usability
                          • Preserve battery life

                        • System resources are shared by all apps
                        • Multitasking apps should minimize CPU & memory
                          footprint in the background




                          | The Junction                                   36

Sunday, July 31, 2011
MEMORY

           • Apps share a limited amount of memory
           • iOS ensures it has the memory it needs
             • Sending apps memory warnings
             • Terminates apps
           • Priority
             • Suspended (high memory usage)
             • Background (high memory usage)
             • Suspended (low memory usage)
             • Background (low memory usage)
             • ...
           • “Termination due to low memory is a normal condition”

                        | The Junction                               37

Sunday, July 31, 2011
MEMORY
                Memory Warnings


                •       iOS sends notifications to running apps to free memory
                •       Only sends warnings when freeing memory is crucial
                •       Suspended apps do not receive memory warnings!!!
                •       Reduce memory use in applicationDidEnterBackground:




                          | The Junction                                        38

Sunday, July 31, 2011
MEMORY

              • OS and frameworks free some memory going to the background
              • Apps using less than 16 MB of dirty memory are written to disk
              • Balance memory footprint and speed to resume




                        | The Junction                                      39

Sunday, July 31, 2011
MEMORY
                View Backing Stores



                                         Backing Store

                                              CALayer


                                                    UIView




                        | The Junction                       40

Sunday, July 31, 2011
MEMORY
                View Backing Stores


                •       Every UIView has a CALayer
                •       UIViews that draw themselves have bitmap backing stores
                •       iOS frees backing stores
                •       iOS may reclaim backing stores while app is running in the
                        background
                • If reclaimed, iOS will call your -drawRect method
                                                                           Backing
                                                                           Store
                                                                                 CALayer

                                                                                    UIView




                          | The Junction                                                     41

Sunday, July 31, 2011
MEMORY
                        UIImage Cache


                        • UIKit caches images loaded with -[UIImage imageName:]
                        • Cache is purged on entering the background




                           | The Junction                                         42

Sunday, July 31, 2011
MEMORY
                        Disk Caches


                        • Many frameworks cache data in memory
                          • SQLite
                          • Core Data
                          • NSCache
                          • ...
                        • Caches are emptied automatically when entering background




                           | The Junction                                        43

Sunday, July 31, 2011
CALayer

                MEMORY
                                                                          UIView
                        UIImageViews


                        •   UIImageViews also have CALayer
                        •   CALayer uses the image directly
                        •   Images are not automatically reclaimed
                        •   Detach large images from the view hierarchy
                        •   Unload offscreen UIImageViews
                        •   Beware of decompression on resume
                            • “The more you release the more time you need to resume”




                            | The Junction                                          44

Sunday, July 31, 2011
MEMORY
                        Caches


                • Flush application caches
                • But not if resuming takes as long as resuming
                • Consider using NSCache and NSPurgeableData:
                  • NSCache
                    • Objects are in memory
                    • Evicts objects as necessary
                    • Evicts objects when entering the background
                  • NSPurgeableData objects in an NSCache are not evicted
                    • Instead they become reclaimable when not in use


                          | The Junction                                    45

Sunday, July 31, 2011
MEMORY
                        Summary


                • Free memory when you receive a memory warning
                • Remove UIImageViews from the view hierarchy unless
                        decompression is a problem
                • Use NSCache and memory-mapped files when appropriate
                • Balance memory footprint and speed to resume




                          | The Junction                                46

Sunday, July 31, 2011
OPEN GL


                • iOS terminates apps that use OpenGL in the background
                • Stop animation timer when entering the background




                        | The Junction                                    47

Sunday, July 31, 2011
OPEN GL
                        Try it yourself
          Exception Type:      EXC_CRASH (SIGABRT)
          ...                                                                                      Foreground
          Thread 0 Crashed:
                                                                                                               Active
          0     libsystem_kernel.dylib         0x33b35a1c __pthread_kill
          1     libsystem_c.dylib              0x30bac3b4 pthread_kill
          2     libsystem_c.dylib              0x30ba4bf8 abort
                                                                                                               Inactive
          3     IMGSGX535GLDriver              0x355229ae glrReturnNotPermittedKillClient
          ...
          7     OpenGLES                       0x354ade4e glFinish
          ...                                                                                    Not Running



                                                                                                   Background

                                                                                            40                 Running



                                                                                                           Suspended




                           | The Junction                                                                                 48

Sunday, July 31, 2011
PRESERVING STATE
                        Common State


                • Return to exactly where you left off
                • Save common UI states
                  • Selected tab bar
                  • Scroll position




                          | The Junction                 49

Sunday, July 31, 2011
PRESERVING STATE
                        App-specific content


                • User input, like the last number entered in Calculator
                • For networking apps, save last search query
                • ...




                           | The Junction                                  50

Sunday, July 31, 2011
PRESERVING STATE
                        Games


                • Turn-by-turn games should save after each turn
                • Games with substantial, frequent state updates save periodically
                  • When the application enters the background
                  • Between levels, rooms




                          | The Junction                                       51

Sunday, July 31, 2011
NETWORKING
                        Sockets and suspension


                • Sockets may disconnect while suspended
                  • Be prepared for errors on resume
                • Suspended apps cannot accept incoming connections
                  • Close listening sockets before suspend
                  • Reopen listening sockets on resume




                           | The Junction                             52

Sunday, July 31, 2011
SYSTEM NOTIFICATIONS


                •       System change notifications not delivered to suspended app
                •       System queues notifications
                •       Delivered when app resumes
                •       Preferences and Locale may be changed in settings app

                                              Event                         Notification

                           Preference changed in Settings   NSUserDefaultsDidChangeNotification

                           Language or locale change        NSCurrentLocaleDidChangeNotification




                          | The Junction                                                          53

Sunday, July 31, 2011
Multitasking And Development




                        | The Junction                      54

Sunday, July 31, 2011
INSTRUMENTS


                • •Applife cycle eventsevents are flagged
                   App
                        life cycles
                                       are flagged




                                                           51




                        | The Junction                          55

Sunday, July 31, 2011
SIMULATOR


                • Simulator is not a replacement for device
                • Supported
                  • Fast app switching
                  • Task completion
                  • Local notifications
                  • Multitasking UI (tray bar)
                • Not supported
                  • Background audio, location and VoIP
                  • Significant location change, region monitoring
                  • Push notifications

                        | The Junction                              56

Sunday, July 31, 2011
DEBUGGER


                • Debugging app changes some behavior!!!
                  • Must-have to test outside the debugger
                • No time limit in UIApplicationDelegate callbacks
                • No time limit in task completion handler




                        | The Junction                               57

Sunday, July 31, 2011
It takes leadership to innovate




                        | The Junction                          58

Sunday, July 31, 2011

More Related Content

Viewers also liked

iOS4 multitasking development notes
iOS4 multitasking development notesiOS4 multitasking development notes
iOS4 multitasking development notesNico Tranquilli
 
In The Brain of Paul Ardeleanu: What's new in iOS 4
In The Brain of Paul Ardeleanu: What's new in iOS 4In The Brain of Paul Ardeleanu: What's new in iOS 4
In The Brain of Paul Ardeleanu: What's new in iOS 4Paul Ardeleanu
 
Networking in iOS NSURLSession & NSStream
Networking in iOS NSURLSession & NSStreamNetworking in iOS NSURLSession & NSStream
Networking in iOS NSURLSession & NSStreamManjula Jonnalagadda
 
iOS 7 URL Session & Motion FX APIs
iOS 7 URL Session & Motion FX APIsiOS 7 URL Session & Motion FX APIs
iOS 7 URL Session & Motion FX APIsrsebbe
 
Background Fetch - the most powerful API you've never heard of
Background Fetch - the most powerful API you've never heard ofBackground Fetch - the most powerful API you've never heard of
Background Fetch - the most powerful API you've never heard ofmoliver816
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your BusinessBarry Feldman
 

Viewers also liked (6)

iOS4 multitasking development notes
iOS4 multitasking development notesiOS4 multitasking development notes
iOS4 multitasking development notes
 
In The Brain of Paul Ardeleanu: What's new in iOS 4
In The Brain of Paul Ardeleanu: What's new in iOS 4In The Brain of Paul Ardeleanu: What's new in iOS 4
In The Brain of Paul Ardeleanu: What's new in iOS 4
 
Networking in iOS NSURLSession & NSStream
Networking in iOS NSURLSession & NSStreamNetworking in iOS NSURLSession & NSStream
Networking in iOS NSURLSession & NSStream
 
iOS 7 URL Session & Motion FX APIs
iOS 7 URL Session & Motion FX APIsiOS 7 URL Session & Motion FX APIs
iOS 7 URL Session & Motion FX APIs
 
Background Fetch - the most powerful API you've never heard of
Background Fetch - the most powerful API you've never heard ofBackground Fetch - the most powerful API you've never heard of
Background Fetch - the most powerful API you've never heard of
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
 

Similar to Multitasking in iOS - The Junction

Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1Violeta Salas
 
Bett 2011 draft vers2
Bett 2011 draft vers2Bett 2011 draft vers2
Bett 2011 draft vers2juliancoultas
 
Mobile Outlook 2010 - Where Are We?
Mobile Outlook 2010 - Where Are We?Mobile Outlook 2010 - Where Are We?
Mobile Outlook 2010 - Where Are We?Joseph Labrecque
 
Fjord@ The Future of Broadcasting
Fjord@ The Future of BroadcastingFjord@ The Future of Broadcasting
Fjord@ The Future of BroadcastingFjord
 
Accesibility challenges, tools and applications Spanish accessibility worksho...
Accesibility challenges, tools and applications Spanish accessibility worksho...Accesibility challenges, tools and applications Spanish accessibility worksho...
Accesibility challenges, tools and applications Spanish accessibility worksho...AEGIS-ACCESSIBLE Projects
 
IBM Collaboration Solutions Community Meeting 11/11 - OpenNTF
IBM Collaboration Solutions Community Meeting 11/11 - OpenNTFIBM Collaboration Solutions Community Meeting 11/11 - OpenNTF
IBM Collaboration Solutions Community Meeting 11/11 - OpenNTFNiklas Heidloff
 
Guide Dogs and Digital Devices
Guide Dogs and Digital DevicesGuide Dogs and Digital Devices
Guide Dogs and Digital DevicesXamarin
 
iOS 5 Tech Talk World Tour 2011 draft001
iOS 5 Tech Talk World Tour 2011 draft001iOS 5 Tech Talk World Tour 2011 draft001
iOS 5 Tech Talk World Tour 2011 draft001Alexandru Terente
 
How to open source a project at Mega Corp (Geecon - May/2011)
How to open source a project at Mega Corp (Geecon - May/2011)How to open source a project at Mega Corp (Geecon - May/2011)
How to open source a project at Mega Corp (Geecon - May/2011)Martijn Verburg
 
Starting an Open Source Project: 0-100k Users - China Mobile Summit 2015 - EN
Starting an Open Source Project: 0-100k Users - China Mobile Summit 2015 - ENStarting an Open Source Project: 0-100k Users - China Mobile Summit 2015 - EN
Starting an Open Source Project: 0-100k Users - China Mobile Summit 2015 - ENDan Cuellar
 
Dev+ops+org how we are including (almost) everyone
Dev+ops+org how we are including (almost) everyoneDev+ops+org how we are including (almost) everyone
Dev+ops+org how we are including (almost) everyonepswartout
 
An Introduction To Mobile Software Testing
An Introduction To Mobile Software TestingAn Introduction To Mobile Software Testing
An Introduction To Mobile Software TestingStephen Janaway
 
Best Mobile UI Practices - FITC Mobile 2010
Best Mobile UI Practices - FITC Mobile 2010Best Mobile UI Practices - FITC Mobile 2010
Best Mobile UI Practices - FITC Mobile 2010Boris Chan
 
02 Objective C
02 Objective C02 Objective C
02 Objective CMahmoud
 
Mobile Testing, That's Just A Smaller Screen, Right?
Mobile Testing, That's Just A Smaller Screen, Right?Mobile Testing, That's Just A Smaller Screen, Right?
Mobile Testing, That's Just A Smaller Screen, Right?Stephen Janaway
 
Experiences with openEyA-Lecture Capture System (Pros and Cons)
Experiences with openEyA-Lecture Capture System (Pros and Cons)Experiences with openEyA-Lecture Capture System (Pros and Cons)
Experiences with openEyA-Lecture Capture System (Pros and Cons)Sara Valla
 
Tomorrow's television today
Tomorrow's television todayTomorrow's television today
Tomorrow's television todayNick DeMartino
 

Similar to Multitasking in iOS - The Junction (20)

Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
 
Bett 2011 draft vers2
Bett 2011 draft vers2Bett 2011 draft vers2
Bett 2011 draft vers2
 
Mobile Outlook 2010 - Where Are We?
Mobile Outlook 2010 - Where Are We?Mobile Outlook 2010 - Where Are We?
Mobile Outlook 2010 - Where Are We?
 
Fjord@ The Future of Broadcasting
Fjord@ The Future of BroadcastingFjord@ The Future of Broadcasting
Fjord@ The Future of Broadcasting
 
Accesibility challenges, tools and applications Spanish accessibility worksho...
Accesibility challenges, tools and applications Spanish accessibility worksho...Accesibility challenges, tools and applications Spanish accessibility worksho...
Accesibility challenges, tools and applications Spanish accessibility worksho...
 
IBM Collaboration Solutions Community Meeting 11/11 - OpenNTF
IBM Collaboration Solutions Community Meeting 11/11 - OpenNTFIBM Collaboration Solutions Community Meeting 11/11 - OpenNTF
IBM Collaboration Solutions Community Meeting 11/11 - OpenNTF
 
Guide Dogs and Digital Devices
Guide Dogs and Digital DevicesGuide Dogs and Digital Devices
Guide Dogs and Digital Devices
 
iOS 5 Tech Talk World Tour 2011 draft001
iOS 5 Tech Talk World Tour 2011 draft001iOS 5 Tech Talk World Tour 2011 draft001
iOS 5 Tech Talk World Tour 2011 draft001
 
How to open source a project at Mega Corp (Geecon - May/2011)
How to open source a project at Mega Corp (Geecon - May/2011)How to open source a project at Mega Corp (Geecon - May/2011)
How to open source a project at Mega Corp (Geecon - May/2011)
 
Mobile web volunteers
Mobile web volunteersMobile web volunteers
Mobile web volunteers
 
M3 conf
M3 confM3 conf
M3 conf
 
Starting an Open Source Project: 0-100k Users - China Mobile Summit 2015 - EN
Starting an Open Source Project: 0-100k Users - China Mobile Summit 2015 - ENStarting an Open Source Project: 0-100k Users - China Mobile Summit 2015 - EN
Starting an Open Source Project: 0-100k Users - China Mobile Summit 2015 - EN
 
Dev+ops+org how we are including (almost) everyone
Dev+ops+org how we are including (almost) everyoneDev+ops+org how we are including (almost) everyone
Dev+ops+org how we are including (almost) everyone
 
An Introduction To Mobile Software Testing
An Introduction To Mobile Software TestingAn Introduction To Mobile Software Testing
An Introduction To Mobile Software Testing
 
Best Mobile UI Practices - FITC Mobile 2010
Best Mobile UI Practices - FITC Mobile 2010Best Mobile UI Practices - FITC Mobile 2010
Best Mobile UI Practices - FITC Mobile 2010
 
02 Objective C
02 Objective C02 Objective C
02 Objective C
 
Mobile Testing, That's Just A Smaller Screen, Right?
Mobile Testing, That's Just A Smaller Screen, Right?Mobile Testing, That's Just A Smaller Screen, Right?
Mobile Testing, That's Just A Smaller Screen, Right?
 
Experiences with openEyA-Lecture Capture System (Pros and Cons)
Experiences with openEyA-Lecture Capture System (Pros and Cons)Experiences with openEyA-Lecture Capture System (Pros and Cons)
Experiences with openEyA-Lecture Capture System (Pros and Cons)
 
Webops dashboards
Webops dashboardsWebops dashboards
Webops dashboards
 
Tomorrow's television today
Tomorrow's television todayTomorrow's television today
Tomorrow's television today
 

Recently uploaded

Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 

Recently uploaded (20)

Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 

Multitasking in iOS - The Junction

  • 1. | The Junction Sunday, July 31, 2011
  • 2. Multitasking in iOS The Junction Ori Goshen Co-Founder & Chief Architect mail: ori@tawkon.com twitter: @origoshen | The Junction 2 Sunday, July 31, 2011
  • 3. OUTLINE • Introduction • Multitasking In iOS Overview • Application Life Cycle • Best Practices • Multitasking & Development Tools | The Junction 3 Sunday, July 31, 2011
  • 4. Introduction | The Junction 4 Sunday, July 31, 2011
  • 5. ME • Coder since birth • IDF (8200) - Project manager & dev. team leader • Fring - Product & development team leader • Tawkon - Co-Founder & Chief Architect • Love & hate relationship with  | The Junction 5 Sunday, July 31, 2011
  • 6. ABOUT TAWKON Drive Safely Eat Wisely Talk Responsibly | The Junction 6 Sunday, July 31, 2011
  • 7. ABOUT TAWKON | The Junction 7 Sunday, July 31, 2011
  • 8. HOW APPLE THINKS? | The Junction 8 Sunday, July 31, 2011
  • 9. MIND & SPIRIT • Watch Apple Engineering Video Tutorials • Watch WWDC Technical Sessions & Keynote • Read The Guidelines! It’s NOT A Waste Of Time • Read Coding Documentation • Follow Apple Evangelists On Twitter • Follow @gruber • Go to macrumors.com • Go to tuaw.com (how I found my iPhone) | The Junction 9 Sunday, July 31, 2011
  • 10. Multitasking In iOS Overview | The Junction 10 Sunday, July 31, 2011
  • 11. INTRODUCTION • A major feature introduced in iOS 4 • Improves user experience • “Every app should adopt multitasking” • Supported on all iOS Devices • Except old ones (iPhone, iPhone 3G, 1st gen. touch) • Android vs. iPhone Multitasking • Multitasking Android Campaign | The Junction 11 Sunday, July 31, 2011
  • 12. iOS MULTITASKING PHILOSOPHY • “General purpose concurrency is not the solution for mobile devices” Background execution: finish task, audio, location, VoIP Push Notification Fast App Switching | The Junction 12 Sunday, July 31, 2011
  • 13. THE SERVICES • Fast App Switching • Resume quickly, preserve state • Push Notifications • Respond to a notification sent from a remote server • Local Notifications • Push-style notification delivered at a predetermined time • NewsStand Push Notification (New on iOS 5) | The Junction 13 Sunday, July 31, 2011
  • 14. THE SERVICES • Background audio • Play audible content to the user while in the background • Task completion • Extra time to complete a task • Location-Navigation • Keep users continuously informed of their location • Location-Significant location change, region monitoring • Respond to location changes while in the background • Voice over IP • Make and receive phone calls using an Internet connection | The Junction 14 Sunday, July 31, 2011
  • 15. | The Junction 15 Sunday, July 31, 2011
  • 16. DO YOU REALLY NEED TO MULTITASK? | The Junction 16 Sunday, July 31, 2011
  • 17. WHAT IF... I’M DOING SOMETHING ELSE? • Triple check if this is something that can be done remotely • Server side push notifications • Daemons (Jailbroken Option) • Mmmm....What about a clipboard history app? • Piggyback on available scenario and think of a damn good excuse (you gonna need it!) | The Junction 17 Sunday, July 31, 2011
  • 18. FAST APP SWITCHING • App Resumes Immediately • App State Is Preserved • Tight integration with multitasking UI • Default for all apps being developed on SDK 4+ • In other words: “processes are being suspended” | The Junction 18 Sunday, July 31, 2011
  • 19. TASK COMPLETION • Application can complete a task without remaining in the foreground • User does not have to wait for the task to complete • Task duration is limited to avoid excessive battery drain • Examples: • Uploading photos or videos • Finishes applying an image filter • Finishes downloading a magazine | The Junction 19 Sunday, July 31, 2011
  • 20. BACKGROUND AUDIO • Plays audible content to the user • Streams audio • Record audio • Continue playing/recording in the background • Integrates with remote controls | The Junction 20 Sunday, July 31, 2011
  • 21. LOCATION NAVIGATION • Keep users informed of their location in the background • Gives turn-by-turn directions | The Junction 21 Sunday, July 31, 2011
  • 22. LOCATION TRACKING • Respond to location changes while in the background • Suitable for location aware apps • Significant location changes • Sends notification after changing cell towers • Region monitoring • Sends a notification upon entering and exiting regions of interest • Not supported on old iPhone (3G, 3GS, ..) | The Junction 22 Sunday, July 31, 2011
  • 23. LOCATION TRACKING Significant location changes Significant location changes Location Location Location changed changed changed 57 | The Junction 23 Sunday, July 31, 2011
  • 24. LOCATION TRACKING Region monitoring Region monitoring Entered region 62 | The Junction 24 Sunday, July 31, 2011
  • 25. VOIP • Helps you maintain the connection with the VOIP server • Keep alive with the server (min. of 10 mins.) • Maintain a signaling connection • Notifying the user on incoming call | The Junction 25 Sunday, July 31, 2011
  • 26. Application Life Cycle | The Junction 26 Sunday, July 31, 2011
  • 27. APPLICATION LIFE CYCLE Launch and active/inactive Foreground Active Inactive Not Running Background Running Suspended | The Junction 27 Sunday, July 31, 2011
  • 28. APPLICATION LIFE CYCLE Launch and active/inactive Foreground Active Inactive Not Running Background Running Suspended | The Junction 27 Sunday, July 31, 2011
  • 29. APPLICATION LIFE CYCLE Launch and active/inactive Foreground Active Inactive applicationDidFinishLaunchingWith Options: Not Running Background Running Suspended | The Junction 27 Sunday, July 31, 2011
  • 30. APPLICATION LIFE CYCLE Launch and active/inactive Foreground Active Inactive applicationDidFinishLaunchingWith Options: Not Running Background Running Suspended | The Junction 27 Sunday, July 31, 2011
  • 31. APPLICATION LIFE CYCLE Launch and active/inactive Foreground applicationDidBecomeActive: Active Inactive applicationDidFinishLaunchingWith Options: Not Running Background Running Suspended | The Junction 27 Sunday, July 31, 2011
  • 32. APPLICATION LIFE CYCLE Launch and active/inactive Foreground applicationDidBecomeActive: Active Inactive applicationDidFinishLaunchingWith Options: Not Running Background Running Suspended | The Junction 27 Sunday, July 31, 2011
  • 33. APPLICATION LIFE CYCLE Launch and active/inactive Foreground applicationDidBecomeActive: Active applicationWillResignActive: Inactive applicationDidFinishLaunchingWith Options: Not Running Background Running Suspended | The Junction 27 Sunday, July 31, 2011
  • 34. APPLICATION LIFE CYCLE Switch from an app Foreground Active Inactive Not Running Background Running Suspended | The Junction 28 Sunday, July 31, 2011
  • 35. APPLICATION LIFE CYCLE Switch from an app Foreground Active Inactive Not Running Background Running Suspended | The Junction 28 Sunday, July 31, 2011
  • 36. APPLICATION LIFE CYCLE Switch from an app Foreground Active applicationWillResignActive: Inactive Not Running Background Running Suspended | The Junction 28 Sunday, July 31, 2011
  • 37. APPLICATION LIFE CYCLE Switch from an app Foreground Active applicationWillResignActive: Inactive Not Running Background Running Suspended | The Junction 28 Sunday, July 31, 2011
  • 38. APPLICATION LIFE CYCLE Switch from an app Foreground Active applicationWillResignActive: Inactive applicationDidEnterBackground: Not Running Background Running Suspended | The Junction 28 Sunday, July 31, 2011
  • 39. APPLICATION LIFE CYCLE Switch from an app Foreground Active applicationWillResignActive: Inactive applicationDidEnterBackground: Not Running Background Running Suspended | The Junction 28 Sunday, July 31, 2011
  • 40. APPLICATION LIFE CYCLE Switch from an app Foreground Active applicationWillResignActive: Inactive applicationDidEnterBackground: Not Running Background Running Suspended | The Junction 28 Sunday, July 31, 2011
  • 41. APPLICATION LIFE CYCLE Switch to an app Foreground Active Inactive Not Running Background Running Suspended | The Junction 29 Sunday, July 31, 2011
  • 42. APPLICATION LIFE CYCLE Switch to an app Foreground Active Inactive Not Running Background Running Suspended | The Junction 29 Sunday, July 31, 2011
  • 43. APPLICATION LIFE CYCLE Switch to an app Foreground Active Inactive Not Running Background Running Suspended | The Junction 29 Sunday, July 31, 2011
  • 44. APPLICATION LIFE CYCLE Switch to an app Foreground Active Inactive Not Running Background Running Suspended | The Junction 29 Sunday, July 31, 2011
  • 45. APPLICATION LIFE CYCLE Switch to an app Foreground Active Inactive applicationDidEnterForeground: Not Running Background Running Suspended | The Junction 29 Sunday, July 31, 2011
  • 46. APPLICATION LIFE CYCLE Switch to an app Foreground Active Inactive applicationDidEnterForeground: Not Running Background Running Suspended | The Junction 29 Sunday, July 31, 2011
  • 47. APPLICATION LIFE CYCLE Switch to an app Foreground Active applicationDidBecomeActive: Inactive applicationDidEnterForeground: Not Running Background Running Suspended | The Junction 29 Sunday, July 31, 2011
  • 48. APPLICATION LIFE CYCLE Termination Foreground Active Inactive Not Running Background Running Suspended | The Junction 30 Sunday, July 31, 2011
  • 49. APPLICATION LIFE CYCLE Termination Foreground Active Inactive Not Running Background Running Suspended | The Junction 30 Sunday, July 31, 2011
  • 50. APPLICATION LIFE CYCLE Termination Foreground Active Inactive Not Running applicationWillTerminate: Background Running Suspended | The Junction 30 Sunday, July 31, 2011
  • 51. APPLICATION LIFE CYCLE Termination Foreground Active Inactive Not Running applicationWillTerminate: Background Running Suspended | The Junction 30 Sunday, July 31, 2011
  • 52. APPLICATION LIFE CYCLE Termination Foreground Active Inactive Not Running applicationWillTerminate: Background Running Suspended | The Junction 30 Sunday, July 31, 2011
  • 53. LIFE CYCLE NOTIFICATIONS UIApplicationDelegate Callback Notification application:didFinishLaunchingWithOptions: UIApplicationDidFinishLaunchingNotification applicationWillTerminate: UIApplicationWillTerminateNotification applicationDidBecomeActive: UIApplicationDidBecomeActiveNotification applicationWillResignActive: UIApplicationWillResignActiveNotification applicationDidEnterBackground: UIApplicationDidEnterBackgroundNotification applicationWillEnterForeground: UIApplicationWillEnterForegroundNotification | The Junction 31 Sunday, July 31, 2011
  • 54. Best Practices | The Junction 32 Sunday, July 31, 2011
  • 55. BEST PRACTICES OUTLINE • System Resources • Memory • OpenGL • Gracefully resuming from the background • Preserving state • Networking • System notifications | The Junction 33 Sunday, July 31, 2011
  • 56. SYSTEM RESOURCES 17 | The Junction 34 Sunday, July 31, 2011
  • 57. RESOURCE MANAGEMENT • Apps share system resources: • CPU • I/O • Memory • GPU • Network | The Junction 35 Sunday, July 31, 2011
  • 58. RESOURCE MANAGEMENT • Goals • Preserve foreground app usability • Preserve battery life • System resources are shared by all apps • Multitasking apps should minimize CPU & memory footprint in the background | The Junction 36 Sunday, July 31, 2011
  • 59. MEMORY • Apps share a limited amount of memory • iOS ensures it has the memory it needs • Sending apps memory warnings • Terminates apps • Priority • Suspended (high memory usage) • Background (high memory usage) • Suspended (low memory usage) • Background (low memory usage) • ... • “Termination due to low memory is a normal condition” | The Junction 37 Sunday, July 31, 2011
  • 60. MEMORY Memory Warnings • iOS sends notifications to running apps to free memory • Only sends warnings when freeing memory is crucial • Suspended apps do not receive memory warnings!!! • Reduce memory use in applicationDidEnterBackground: | The Junction 38 Sunday, July 31, 2011
  • 61. MEMORY • OS and frameworks free some memory going to the background • Apps using less than 16 MB of dirty memory are written to disk • Balance memory footprint and speed to resume | The Junction 39 Sunday, July 31, 2011
  • 62. MEMORY View Backing Stores Backing Store CALayer UIView | The Junction 40 Sunday, July 31, 2011
  • 63. MEMORY View Backing Stores • Every UIView has a CALayer • UIViews that draw themselves have bitmap backing stores • iOS frees backing stores • iOS may reclaim backing stores while app is running in the background • If reclaimed, iOS will call your -drawRect method Backing Store CALayer UIView | The Junction 41 Sunday, July 31, 2011
  • 64. MEMORY UIImage Cache • UIKit caches images loaded with -[UIImage imageName:] • Cache is purged on entering the background | The Junction 42 Sunday, July 31, 2011
  • 65. MEMORY Disk Caches • Many frameworks cache data in memory • SQLite • Core Data • NSCache • ... • Caches are emptied automatically when entering background | The Junction 43 Sunday, July 31, 2011
  • 66. CALayer MEMORY UIView UIImageViews • UIImageViews also have CALayer • CALayer uses the image directly • Images are not automatically reclaimed • Detach large images from the view hierarchy • Unload offscreen UIImageViews • Beware of decompression on resume • “The more you release the more time you need to resume” | The Junction 44 Sunday, July 31, 2011
  • 67. MEMORY Caches • Flush application caches • But not if resuming takes as long as resuming • Consider using NSCache and NSPurgeableData: • NSCache • Objects are in memory • Evicts objects as necessary • Evicts objects when entering the background • NSPurgeableData objects in an NSCache are not evicted • Instead they become reclaimable when not in use | The Junction 45 Sunday, July 31, 2011
  • 68. MEMORY Summary • Free memory when you receive a memory warning • Remove UIImageViews from the view hierarchy unless decompression is a problem • Use NSCache and memory-mapped files when appropriate • Balance memory footprint and speed to resume | The Junction 46 Sunday, July 31, 2011
  • 69. OPEN GL • iOS terminates apps that use OpenGL in the background • Stop animation timer when entering the background | The Junction 47 Sunday, July 31, 2011
  • 70. OPEN GL Try it yourself Exception Type: EXC_CRASH (SIGABRT) ... Foreground Thread 0 Crashed: Active 0 libsystem_kernel.dylib 0x33b35a1c __pthread_kill 1 libsystem_c.dylib 0x30bac3b4 pthread_kill 2 libsystem_c.dylib 0x30ba4bf8 abort Inactive 3 IMGSGX535GLDriver 0x355229ae glrReturnNotPermittedKillClient ... 7 OpenGLES 0x354ade4e glFinish ... Not Running Background 40 Running Suspended | The Junction 48 Sunday, July 31, 2011
  • 71. PRESERVING STATE Common State • Return to exactly where you left off • Save common UI states • Selected tab bar • Scroll position | The Junction 49 Sunday, July 31, 2011
  • 72. PRESERVING STATE App-specific content • User input, like the last number entered in Calculator • For networking apps, save last search query • ... | The Junction 50 Sunday, July 31, 2011
  • 73. PRESERVING STATE Games • Turn-by-turn games should save after each turn • Games with substantial, frequent state updates save periodically • When the application enters the background • Between levels, rooms | The Junction 51 Sunday, July 31, 2011
  • 74. NETWORKING Sockets and suspension • Sockets may disconnect while suspended • Be prepared for errors on resume • Suspended apps cannot accept incoming connections • Close listening sockets before suspend • Reopen listening sockets on resume | The Junction 52 Sunday, July 31, 2011
  • 75. SYSTEM NOTIFICATIONS • System change notifications not delivered to suspended app • System queues notifications • Delivered when app resumes • Preferences and Locale may be changed in settings app Event Notification Preference changed in Settings NSUserDefaultsDidChangeNotification Language or locale change NSCurrentLocaleDidChangeNotification | The Junction 53 Sunday, July 31, 2011
  • 76. Multitasking And Development | The Junction 54 Sunday, July 31, 2011
  • 77. INSTRUMENTS • •Applife cycle eventsevents are flagged App life cycles are flagged 51 | The Junction 55 Sunday, July 31, 2011
  • 78. SIMULATOR • Simulator is not a replacement for device • Supported • Fast app switching • Task completion • Local notifications • Multitasking UI (tray bar) • Not supported • Background audio, location and VoIP • Significant location change, region monitoring • Push notifications | The Junction 56 Sunday, July 31, 2011
  • 79. DEBUGGER • Debugging app changes some behavior!!! • Must-have to test outside the debugger • No time limit in UIApplicationDelegate callbacks • No time limit in task completion handler | The Junction 57 Sunday, July 31, 2011
  • 80. It takes leadership to innovate | The Junction 58 Sunday, July 31, 2011