0

I want to index multiple NSUserActivities of same type. The code for the same is given below:

-(void)createActivityForEachCity:(NSNotification *)notification
{
    NSArray *nameList = @[@"name1",@"name2",@"name3",@"name4"];
    if (nameList)
    {
        for (NSString *name in nameList)
        {
            [self createIndexActivityForName:name];
        }
    }
}

-(void)createIndexActivityForName:(NSString*)name
{
    NSUserActivity *activity = [[NSUserActivity alloc]initWithActivityType:@"spotlightsearchactivity"];
    NSDictionary *activityUserInfo = @{@"name":name};
    activity.userInfo = activityUserInfo;
    activity.title = [NSString stringWithFormat:@"You Searched for %@",name];
    activity.eligibleForHandoff = NO;
    activity.eligibleForSearch = YES;
    activity.eligibleForPublicIndexing = YES;
    self.userActivity = activity;
    [activity becomeCurrent];
}

From the above code, NSUserActivities for name1, name2, name3 and name4 must be created. But what I am getting is, the NSUseractivity are being overridden i.e., only name4 is getting indexed.

What is missing in the code?

halfer
  • 19,824
  • 17
  • 99
  • 186
PGDev
  • 23,751
  • 6
  • 34
  • 88
  • everytime NSUserActivity *activity = [[NSUserActivity alloc]initWithActivityType:@"spotlightsearchactivity"]; will be created. so it will replace the old values. – Rince Thomas Feb 08 '16 at 06:42
  • but we can create multiple NSUserActivities of same activity type.This [Tutorial](http://code.tutsplus.com/tutorials/ios-9-introducing-search-apis--cms-24375) also uses same activity type for indexing different `NSUserActivities`. – PGDev Feb 08 '16 at 07:10
  • @PGDev : did you find any success? Actually, I also facing same issue. – girish_pro Aug 04 '17 at 09:20

0 Answers0