iOS 9.2,xCode 7.2,Objective-C
我使用了本教程(Core Spotlight版本),但将其转换为Objective-C: http://code.tutsplus.com/tutorials/ios-9-introducing-search-apis--cms-24375
除了一件事之外,一切都有效 - 当用户点击搜索结果时,我无法进行回调。我似乎需要在我的app delegate中编写以下方法:
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler
但根本没有召唤它。如何解决这个问题?
答案 0 :(得分:3)
您必须先检查您的活动是否有类型搜索操作:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler
{
if ([[userActivity activityType] isEqualToString:CSSearchableItemActionType])
{
NSString *uniqueIdentifier = [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier];
NSLog(@"%@",uniqueIdentifier);
// Launch Detail controller
}
return YES;
}
希望它可以帮到你!!