Example: App contains messages. User searches spotlight with string from message. Spotlight finds that app.
I have heard that spotlight can search app contents. But how to feed it to Spotlight on iOS?
Example: App contains messages. User searches spotlight with string from message. Spotlight finds that app.
I have heard that spotlight can search app contents. But how to feed it to Spotlight on iOS?
According to the Core Data Spotlight Integration Programming Guide, the functionality you want is not available for iOS, only for Mac OS X.
This is now possible from iOS9 onwards.
Apple has released a CoreSpotlight SDK (WWDC2015) where, you can integrate your app to the spotlight of iOS and can do a content search.
There are other possible avenues to actually integrate different user activities to your app and can also search for things even when your app is not installed on the device.
If your app is an app that handles pdf for instance, if user searches for a pdf on his device, you app can come up in the spotlight preferences as an app he can use to read the pdf, even when your app is not installed on the user's device.
Considering your example, now its possible that if you search for a message string in spotlight, spotlight can open up your app and you can make the user actually navigate to find the exact message inside your app as well.
Adding link below : You can find details for implementation.
-Tejas
Here is an example of adding your app content to Spotlight via the new Search API's. This is available on iOS9 using XCode 7.
CSSearchableItemAttributeSet * attributes = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeImage]; //Or whatever type
attributes.contentDescription = @"This is my content description.";
attributes.displayName = @"Display Name";
attributes.keywords = @["Stuff","Widget"];
attributes.subject = @"Subject";
attributes.title = @"Title";
CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:someUniqueId domainIdentifier:@"SomeGroupName" attributeSet:attributes];
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler:nil];
When the user selects the item in spotlight, the following method:
-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler
in your AppDelegate will be called. Check the userInfo dictionary in the userActivity object and send the user to the appropriate screen.
I have created a sample project to integrate corespotlgiht feature. It works on iOS 9 and requires Xcode 7 beta 2 to build. You can try out if it helps. https://github.com/majain/iPhoneCoreDataRecipes
Video link for the same is: https://youtu.be/Renm1xLDIFc
© 2022 - 2024 — McMap. All rights reserved.