[Spotlight] deleteAllSearchableItemsWithCompletionHandler is not working If identifier isn't in English.

Sample Code

- (void)spotlightTest {

  
    self.dummyList = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < 10; i++) {
        [self.dummyList addObject:[NSString stringWithFormat:@"iMac%ld MacBook%ld iPhone%ld", i, i, i]];
    }

    NSMutableArray *searchableItems = [[NSMutableArray alloc] init];
    NSMutableArray *identifierlist  = [[NSMutableArray alloc] init];


  
    for (NSString *name in self.dummyList) {
     
      
        if (name != nil) {
         
          
            CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString*)kUTTypeText];
            attributeSet.title = @"Test Spotlight";
            attributeSet.contentDescription = name;
         
          
            NSMutableArray *keywords = [[NSMutableArray alloc] initWithArray:[name componentsSeparatedByString:@" "]];
            if ([keywords count] > 1) {
                [keywords addObject:name];
            }
            attributeSet.keywords = keywords;
         
           // Identifier isn't English (Ex.include Korean, ect)
            NSString *identifier = [NSString stringWithFormat:@"com.(OOO).test.%@", name];   // OOO Korean, Chinese, ect    
        
         
          
            CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:identifier domainIdentifier:@"TestDomain" attributeSet:attributeSet];
            [searchableItems addObject:item];
         
         
            NSLog(@"keywords: %@", name);
         
        } else {
            NSLog(@"Warning: Failed to get a hotel name. This hotel will not be set in spotlight indices.");
        }
    }


    // Indexing
    [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:searchableItems completionHandler: ^(NSError * __nullable error) {
        if (error == nil) {
            NSLog(@"Searchable items indexed.");
        } else {
            NSLog(@"Error: %@", [error description]);
        }
     
    }];


    // Deleting is not working
    [[CSSearchableIndex defaultSearchableIndex] deleteSearchableItemsWithIdentifiers:identifierlist completionHandler:^(NSError * _Nullable error) {
        if (error == nil) {
            NSLog(@"searchable itmes deleted successfully.");
        } else {
            NSLog(@"Error: %@", [error description]);
        }
    }];

}



Spotlight indices remain still, If searchableItem Identifier is not in English ( Ex. Korean)
Also, If I delete the app, I can still search searchableItem in Spotlight.


It's the only way that is reset all.


How can I delete searchable items, when Identifier isn't in English.

Replies

has this been resolved? we are also facing the same problem

I'm seeing the same thing even for identifiers in english/alphanumeric.


I noticed the documentation says:


The block that’s called when the request has been journaled by the index (“journaled” means that the index makes a note that it has to perform this operation). Note that the request may not have completed.


but no idea how long it takes for the delete to stick.