Is it possible to use the new features of iOS9 such as NSUserActivity
and CoreSpotlight
, but still set my Development Target to 8.2 so that users with iOS8 can still use the app?
I assume I would just need to do a iOS version number check or use respondsToSelector:
.
Is this correct?
Yes, I do it in one of my apps (actually have a deployment target of iOS 7). It's trivial to do. Just make sure the CSSearchableIndex
class exists, make the CoreSpotlight
framework optional, and write your code properly to prevent the newer APIs from being run on devices with earlier versions of iOS.
You can even guard the code so it compiles under Xcode 6 if you had some reason to do so.
Example:
// Ensure it only compiles with the Base SDK of iOS 9 or later
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
// Make sure the class is available and the device supports CoreSpotlight
if ([CSSearchableIndex class] && [CSSearchableIndex isIndexingAvailable]) {
dispatch_async(_someBGQueue, ^{
NSString *someName = @"Some Name";
CSSearchableIndex *index = [[CSSearchableIndex alloc] initWithName:someName];
// rest of needed code to index with Core Spotlight
});
}
#endif
In your app delegate:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler {
if ([[userActivity activityType] isEqualToString:CSSearchableItemActionType]) {
// This activity represents an item indexed using Core Spotlight, so restore the context related to the unique identifier.
// The unique identifier of the Core Spotlight item is set in the activity’s userInfo for the key CSSearchableItemActivityIdentifier.
NSString *uniqueIdentifier = [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier];
if (uniqueIdentifier) {
// process the identifier as needed
}
}
return NO;
}
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With