Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if an iPad is capable of multitasking feature in iOS 9 - Programatically

For iPad Air 2 or an iPad mini 4, we can use all three of the different multi-tasking features (Split View, Slide over & Picture in Picture). For iPad Air, iPad mini 2, or iPad mini 3, we can use Slide Over and Picture in Picture. Is there a way we can detect these devices from the code? Like say, using respondsToSelector:someMultitaskingmethod?

like image 452
Siddharthan Asokan Avatar asked Nov 14 '15 00:11

Siddharthan Asokan


1 Answers

Device Compatibility

If you really want to make sure your device has specific compatibility you can examine the settings over on the Device Compatibility list. This will reveal a number of keys that you can add to your app's plist which will further restrict it to devices that support required features. Together with checking for available classes mentioned below, I think would provide a good matrix for what you want to accomplish.

A quick review of the WWDC video covering the features you want to support indicate that you will need to check for the iPad Air, iPad Air2, iPad mini 2 and 3. You can take a look at the screen sizes in combination with the idioms and class availability to ensure that you target only the devices you want. IOSRES has a good matrix of these screen sizes ~ accessed by UIScreen.mainScreen().

Another option would be to examine using a TraitCollection to identify the proper device models/capabilities. These include properties such as displayScale and forceTouchCapability. One can even construct one's own trait collection to further describe a unique environment.

Basic Approach

Checking for devices alone is probably not what you want to do. Instead you should check for the capability available on the iOS platform and some combination of the device idioms/traits collection. You could then compare whether the method is available using responds to selector.

Check the updated SDKs or the Frameworks for more info on picture in picture (basically the new methods do all of the legwork and tell you whether the device will support the feature). Another precursor to running the methods is to determine if you can instantiate the new classes.

sdk

You can also investigate options for examining specific hardware within the platform. See this example from Apple.

If you know that the features you are targeting are available at specific platform levels, you can test the operation system version number (Apple Example).

+ (BOOL)isURLLoadingAvailable
{
    return (NSFoundationVersionNumber >= 462.6);
}

This article shows how to support multiple OS and devices in great detail.

Example of testing for a class being available:

if ([AVPictureInPictureController class]) {
    //Safe to use AVPictureInPictureController 
} else {
    //Fail gracefully
}

Example of testing a method being available:

if ([self.image respondsToSelector:@selector(resizableImageWithCapInsets:resizingMode:)]) {
    //Safe to use this way of creating resizable images
} else {
    //Fail gracefully
}

Adopting Multi-Tasking, Split View, & Slide Over

Apple details the specifics on how to adopt the new behaviors. These require setup of plists and other requirements above and beyond checking for classes and the other programmatic techniques above. There is a good example of how to adopt Slide Over and Split View, download the Lister (for watchOS, iOS, and OS X) sample code project. For a Picture-In-Picture sample look at the AVFoundationPiPPlayer.The AdaptivePhotos sample includes multitasking with iPad.

like image 163
Tommie C. Avatar answered Oct 01 '22 15:10

Tommie C.