首页 > 解决方案 > 如何在 Corespotlight 搜索中显示消息和视频按钮?

问题描述

当用户搜索我能够显示呼叫按钮但无法显示消息和视频按钮的联系人时,我想显示消息和视频按钮。

下面是我正在使用的一段代码

CSSearchableItemAttributeSet * attributeSet = [[CSSearchableItemAttributeSet alloc]
                                                                   initWithItemContentType:(NSString *)kUTTypeItem];

  attributeSet.displayName = [contact.name.compositeName capitalizedString];
  attributeSet.contentDescription = @"my awesome Contacts ";
  attributeSet.keywords = @[[contact.name.compositeName capitalizedString]];
  UIImage *image = [UIImage imageNamed:@"dialer_filled_icn"];
  NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
   attributeSet.thumbnailData = imageData;
   attributeSet.phoneNumbers = @[JustNumber([contact.phones[0] number])];
   attributeSet.instantMessageAddresses  = @[JustNumber([contact.phones[0] number])];
   attributeSet.supportsPhoneCall =  @(YES);
   CSSearchableItem *item1 = [[CSSearchableItem alloc]
                             initWithUniqueIdentifier:JustNumber([contact.phones[0] number])
                             domainIdentifier:@"com.domain.appname"
                             attributeSet:attributeSet];

   [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item1]
                   completionHandler: ^(NSError * __nullable error) {
                                 if (!error)
                           NSLog(@"Search item(s) journaled for indexing.");
                         }];

任何建议将不胜感激。

标签: iosobjective-ccorespotlight

解决方案


推荐阅读