Hello,
I have the following simple code running in the ViewDidLoad for a simple ViewController:
self.userActivity = [[NSUserActivity alloc]
initWithActivityType:@"com.company.activity-type"];
self.userActivity.title = self.restaurant.name;
self.userActivity.keywords = [NSSet setWithArray:@[@"LOOK",@"HERE"]];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"suge knight", @"killed 2pac", nil];
self.userActivity.userInfo = dict;
CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeImage];
attributeSet.title = @"big hitz";
attributeSet.contentDescription = [NSString stringWithFormat:@"%@\n%@",@"cali",@"rollin'"];
attributeSet.thumbnailData = [NSData dataWithData:UIImagePNGRepresentation(self.restaurant.imageForSpotlight)];
attributeSet.identifier = @"asdf";
self.userActivity.contentAttributeSet = attributeSet;
self.userActivity.requiredUserInfoKeys = [NSSet setWithArray:self.userActivity.userInfo.allKeys];
self.userActivity.eligibleForSearch = YES;
self.userActivity.eligibleForPublicIndexing = YES;
The following code works great and displays the NSUserActivity in spotlight 100% fine. The problem is that if I visit this ViewController multiple times, duplicates of the same NSUserActivity spotlight results come up in spotlight. What can I do to prevent this? I only want one instance of the activity displaying in spotlight.
Thanks for reading.
According to https://developer.apple.com/library/prerelease/ios/technotes/tn2416/_index.html Ideally you'd set a relatedUniqueIdentifier on the attributes but if you do that it won't get indexed at all, so I don't think it's possible with the current state of affairs. *I haven't re-tested under beta 5 yet but Apple marked my Bug Report on this as "works as intended".