Да, я делаю это в одном из моих приложений (на самом деле есть цель развертывания 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
Brilliant! Спасибо! –