NSUserActivity results

In my viewController, I'm creating an NSUserActivity, attaching an CSSearchableItemAttributesSet, assigning the activity to the viewController's userActivity property, and then calling becomeCurrent on the activity as below:


NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:activity.uniqueIdentifier];
CSSearchableItemAttributeSet *attribs = [self attributesForActivity:activity]; //sets title, contentDescription
userActivity.contentAttributeSet = attribs;
userActivity.eligibleForSearch = YES;
userActivity.eligibleForHandoff = YES;
userActivity.eligibleForPublicIndexing = YES;
self.userActivity = userActivity;
[self.userActivity becomeCurrent];


But nothing is showing up. I've tried running this on the simulator and on an iPhone 5 device, but nothing is happening. Can't see any log files to indicate anything is amiss.


If I use Core Spotlight and add the same item to the index, it shows up immediately on both device and simulator. Is the NSUserActivity integration not working yet?

Replies

NSUserActivity does not work on the simulator (either for handoff or for search). This was confirmed to me by an engineer at WWDC 15's "Search API" lab.

What build are you running? Please file a bug report and if you can include a sample project that would be great.

Do you have it working on a device? I can't get it working on a device or the simulator.

Running beta2. (It didn't work on beta1 either)


I'm happy to file a bug report, but I'm only trying the simplest of cases (the code I posted above) and it's not working, which is why I'm asking here first. I'm doing nothing compliated. The code I posted above is basically the whole thing. Wondering if there's some other step I need to take to get the activity to be indexed?


I also tried setting `self.userActivity.needsSave = YES;` for good measure

Yes, please file a bug report. From the looks of the code you pasted above that should be fine (assuming self.userActivity is a strong reference, is it?).

Similarly, please file a bug report with details of what you're doing. What device are you trying to run on?

Creating a test project now.


self.userActivity is the property on UIResponder. (Which the docs list as Strong) - I also tried it with my own strong property which doesn't seem to make any difference.

Filed as 21561771

Terrific, thank you very much! You should not have to set needsSave = YES on the activity. Just making it current should be enough. We're looking at the issues being reported with Seed 2.

FWIW this seems to be working fine in beta 3 on the simulator.

I am having the same problem. Doesn't work on beta 4 either. Does anybody have any ideas how to debug the problem? Has somebody gotten it to work?

I haven't tried on b4. It worked for me on b3 on a device (not iPad2 or iPad mini) and make sure you don't set a relatedUniqueIdentifier if you want it to actually show up in the index.

Has anyone been able to get NSUserActivity to show up on spotlight with the lastest beta? (Beta 6)


I still can't get it to work, but it's fine with CoreSpotlight API.

"still can't get it to work" meaning it's never worked for you in any of the betas? It worked fine for me in beta 4 and 5, 4 quit as the 5 released got nearer though.


I haven't tried my project in 6 yet, actually come to think of it, there was no iOS beta 6 released. So you actually mean 5....


Without seeing your code the only thing I can suggest is to make sure you did not set a `relatedUniqueIdentifier` if you do not have a corresponding Core Spotlight item, that prevented any of my results from appearing.

Same here, testing on Xcode Version 7.0 beta 6 (7A192o), NSUserActivity indexed item never ever shows in my search result. spent my last 4 hours on find solution, reset my simulator, and tweaking my code. nothing helps. Please advise.