A Look at Multi-tasking on the iPad
With iOS 9, certain iPad devices will have multi-tasking capability, or the capability to have a combination of up to two apps and a picture in picture window open at the same time. The iPad Air and the iPad mini 2 or later have Slide Over and picture in picture (PiP) modes. The iPad Air 2, iPad mini 4, and the iPad Pro have those modes and a Split View mode.
For a user to start multi-tasking they slide their finger over from the right-most side of the screen to show the Slide Over mode. The app that starts in full screen is considered the primary app. In the example below the primary app is the Calendar app:
The user then selects an app. Below I have chosen Maps:
In this mode the user can interact with an app in the right panel, called the secondary app. Notice the primary app is in a disabled state and the secondary app is running in the foreground. The left panel is not fully visible as the right panel is overlaid on top of it. Selecting anywhere in the primary app at this point will dismiss the right panel.
If the user selects the bar on the vertical divider, the mode changes to Split View, not to be confused with
The user can slide the divider to change the width of the apps in the Split View.
In another scenario, a multimedia app could start a video, which when placed in the background would show as PiP and could look like the following:
External screens showing iPad content, such as AppleTV, only show the primary app. The primary app owns the status bar and participates in automatic invocation of PiP.
Developing with Multi-tasking
Developers adopt both Size Classes (iOS 8) and Auto Layout (iOS 6) at this point if they have not already. These will allow for smooth transitions as an app is resized during Multi-Tasking. An app not only needs to adjust its layout constraints but also change size classes as a user slides the divider for Multi-tasking.
If an app requires a full screen experience, it may opt out using the
UIRequiresFullscreen key in the
Info.plist. Even for a full screen app however, a developer must still manage their app for multi-tasking. An app designated as requires fullscreen cannot be used as a the secondary app in the Slide Over mode, nor can it be used in a Split View mode. While using an app that requires fullscreen as the primary another app can still be opened in Slide Over mode. This means a developer of a full screen only app must still manage shared resources for multi-tasking.
When creating a new project Xcode adopts multi-tasking by default. To adopt multi-tasking an older app should change the build settings to use iOS 9 and support all interface orientations in the iPad version of the app. In addition to any XIB files, the project is also required to contain a
With multi-tasking an app should refer to the
UIWindow.bounds instead of the
UIScreen.bounds to find its size. Whether it is the primary or secondary app, the upper left corner of the
UIWindow.bounds call will always be (0,0).
To determine when an app is transitioning during multitasking the following methods are called in this order:
animateAlongsideTransition. Be careful that the trait collection may not change during certain transitions and the traitCollections methods above will not fire. An example of a size change with no trait collection change would be a 70-30 Split View mode when the user rotates the device. The secondary app would still have the same traits for size classes of compact width, regular height even though the size of containing window was changed.
Apps Sharing Resources
Only one system keyboard will display. Only one app can use the camera. There is a limited amount of CPU, GPU, memory and disk space. Apps now need to share these resources, which requires developers to make more efficient use of them.
Either the primary of the secondary app may initiate opening the keyboard. Even if an app does not use a keyboard it may need to listen to
UIKeyboard notifications to adjust what is in the visible area when the keyboard could be covering essential parts of an app.
The user controls the size of the app and can change it at anytime. The developer cannot prevent or change its own size. As a user changes from one size or trait to another the app should remain at the same location or task that was last being used. An example of a bad user experience would be if a user was entering a value halfway down a form and then after a trait collection change the form was scrolled to the top.
When the user moves the divider on the Split View (as seen above), the system calls the App Delegate
applicationWillResignActive protocol method. The app should take a snapshot of the last thing a user was doing and return them to the same state (view, selection, scroll position) when the app becomes active again. An app should do as little work as possible during this change. If it does not react fast enough to a size change it will get terminated.
Optimizing An App for Multitasking
A single app may have no issues running at the expected 60 frames per second (fps), however when a secondary app and/or PiP is open at the same time the competing resources for the processor can slow down an app and cause a stuttering experience. If the device comes under memory pressure the system may terminate the app consuming the most memory. Reduce an apps memory by setting up images based on size classes in the image asset folder. Apps can be optimized by fixing memory leaks, retain cycles and inefficient algorithms. Instruments is a great tool for finding memory issues. Another option would be to choose Hardware, then Simulate Memory Warning from the simulator to assess how an app will respond to low memory issues.
Adopt the idea of using just in time or only having in memory what is needed when its needed.
NSPurgableData and Memory Mapped Data are ways to reduce your virtual memory footprint. Maps is a good app to use for testing the strain on the CPU and responsiveness of an app. Putting Maps in satellite view performing a flyover animation increases the strain.
Multi-tasking is an exciting new development for iPads. Users will expect apps to handle multi-tasking, especially for the iPad Pro with so much screen space. Feel free to explore other iOS tutorials at the CapTech blog. If you have questions you may contact me at firstname.lastname@example.org.