CSSearchableItemAttributeSet的contentDescription属性不支持换行格式

时间:2016-08-10 07:19:58

标签: ios objective-c corespotlight

我的CSSearchableItem CSSearchableItemAttributeSet

CSSearchableItemAttributeSet* attributes = [[CSSearchableItemAttributeSet alloc]initWithItemContentType:(__bridge NSString *)kUTTypeContact];
attributes.keywords = @[keywords];
attributes.title = @"Contact Details";
attributes.displayName = @"Ram Gandhi";
attributes.emailAddresses = @[email];
attributes.phoneNumbers = @[phoneNumber];
attributes.contentDescription = [NSString stringWithFormat:@"%@ \n %@", phoneNumber, email];
attributes.supportsPhoneCall = [NSNumber numberWithBool:YES];
attributes.supportsNavigation = [NSNumber numberWithBool:NO];
attributes.thumbnailData = [self getThumbnailData:contactID];

一切正常但contentDescription中的换行符没有按预期工作,尽管UI中没有显示。

此外,我不确定在kUTTypeContact使用kUTTypeContent的目的,因为kUTTypeContact完成了这项工作。就我搜索而言,没有关于如何在Spotlight搜索中使用{{1}}的详细文档。

我是否可以使用其他任何财产以便在单独的行中显示电子邮件和电话号码?

1 个答案:

答案 0 :(得分:0)

这可能对您来说是很晚的答案,但可以帮助其他人。现在,使用swift 4时,我们可以如下添加两行“ contentDescription”,

var contentDescription = ""
var arrDescription = ["email","phone"]
for (index,strDesc) in arrDescription.enumerated(){
    if index == 0{
        contentDescription = strDesc
    }else{
        contentDescription += """

        \(strDesc)
        """
    }
}

我还尝试添加两个以上的字符串,但是它最多只显示两行,然后在第二行的末尾显示...。

注意:-检查“(strDesc)”之前的“空白行”是否正确,必须在其中显示换行符。