2 Replies
      Latest reply on Sep 5, 2019 2:46 PM by adamwulf
      Den Jo Level 1 Level 1 (0 points)

        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.