Ciao Sto cercando di implementare CoreSpotlight nella mia app.Indexing CoreSpotlight
Quando si esegue l'indicizzazione è necessario eseguirlo ogni volta o è sufficiente eseguirlo una volta quando l'app viene installata per la prima volta? Se l'app viene cancellata devo indicizzarmi di nuovo?
Ecco il codice che sto utilizzando:
- (void)spotLightIndexing {
NSString *path = [[NSBundle mainBundle] pathForResource:
@"aDetailed" ofType:@"plist"];
NSDictionary *plistDict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *plistArray = [plistDict allKeys];
for (id key in plistDict) {
CSSearchableItemAttributeSet* attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeImage];
// Set properties that describe attributes of the item such as title, description, and image.
attributeSet.title = key;
attributeSet.contentDescription = [plistDict objectForKey:key];
//*************************************
attributeSet.keywords = plistArray; // Another Q: do i need this????
//**************************************
// Create an attribute set for an item
UIImage *image = [UIImage imageNamed:@"icon.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
attributeSet.thumbnailData = imageData;
// Create a searchable item, specifying its ID, associated domain, and the attribute set you created earlier.
CSSearchableItem *item;
NSString *identifier = [NSString stringWithFormat:@"%@",attributeSet.title];
item = [[CSSearchableItem alloc] initWithUniqueIdentifier:identifier domainIdentifier:@"com.example.apple_sample.theapp.search" attributeSet:attributeSet];
// Index the item.
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler: ^(NSError * __nullable error) {
if (!error)
NSLog(@"Search item indexed");
else {
NSLog(@"******************* E R R O R *********************");
}];
}
}
grazie
Il codice funziona ?? perché quando metto questo codice sul mio compilatore di progetto non mi dà output 'Ricerca elemento indicizzato'! –
@ Mc.Lover sì funziona come un fascino!vedi la risposta MODIFICATA per registrare eventuali errori –
Vuoi dare un'occhiata a questa domanda? http://stackoverflow.com/questions/33443833/set-title-property-from-nsarray-in-cssearchableitemattributeset, ho usato il tuo codice ma non ha funzionato! –