Following is the code that I am trying to implement to make app activities and states searchable but not able to show on iOS search
NSUserActivity *userActivity = [[NSUserActivity alloc]initWithActivityType:@"com.mycompany.activity-type"];
userActivity.title = @"Hello world from in app search";
userActivity.keywords = [NSSet setWithArray:@[@"Hello",@"Welcome", @"search"]];
userActivity.userInfo = @{@"id":@"com.example.state"};
userActivity.eligibleForSearch = YES;
[userActivity becomeCurrent];
Link to make my question more clear.
From the Apple Forums:
One thing that has bitten a few people (myself included) is that the activity must not be deallocated. If your code is only working with NSUserActivities (i.e. not using CoreSpotlight in addition) then make sure your activities aren't being deallocated immediately.
In my case, I had code that was allocating the NSUA, setting some properties on it, calling becomeCurrent, but then the object would go out of scope and deallocated. If you're doing this, try tossing the activity into a strong property to see if you can then see the results when you search.
https://forums.developer.apple.com/message/13640#13640
What I have found is you have to assign the NSUserActivity instance you have created to your currently visible UIViewControllers's userActivity property before calling -becomeCurrent. It has fixed it for me and the items immediately appeared both for handoff on other devices and in spotlight search on the same device.
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