Use NSUserActivity and CoreSpotlight, but still set iOS8 as the deployment target

Is it possible to use new iOS9 features like NSUserActivityand CoreSpotlight, but still set my target to 8.2 so that users with iOS8 can still use the app?

I assume that I just need to check the iOS version number or use respondsToSelector:.

Is it correct?

+4
source share
1 answer

, ( iOS 7). . , CSSearchableIndex , CoreSpotlight , API iOS.

, Xcode 6, .

:

// 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

:

#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
+7

Source: https://habr.com/ru/post/1609707/


All Articles