繁体   English   中英

调用CSSearchableIndex indexSearchableItems时的BAD_ACCESS

[英]BAD_ACCESS when calling CSSearchableIndex indexSearchableItems

我试图在我的应用程序中实现CoreSpotlight API,但似乎无法弄清楚为什么我的实现得到了BAD_ACCESS异常:

CSSearchableItemAttributeSet * attributeSet = [CSSearchableItemAttributeSet new];

attributeSet.title = route.Options.name;
attributeSet.keywords = [route.Options.name componentsSeparatedByString:@" "];

UIImage *image = [UIImage imageNamed:@"pin_busstop.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
attributeSet.thumbnailData = imageData;

CSSearchableItem * item = [[CSSearchableItem alloc] initWithUniqueIdentifier:route.ObjectID domainIdentifier:@"com.whatever.itsmyappsname.loadwithroute" attributeSet:attributeSet];

[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:[NSArray arrayWithObject:item] completionHandler:^(NSError * _Nullable error) {
    NSLog(@"It worked");
}];

查看异常的调用堆栈,我可以看到它发生在CSSearchableIndex indexSearchableItems: completionHandler: call上。 但是我可以在没有异常触发的情况下跳过该调用,也许它与完成处理程序有关,但无论是否有一个,它都会发生。 我在我的.h文件和目标中都导入了CoreSpotlight/CoreSpotlight.hMobileCoreServices/MobileCoreServices.h

你(我)正确地创建了CSSearchableItemAttributeSet对象。 代替:

CSSearchableItemAttributeSet * attributeSet = [CSSearchableItemAttributeSet new];

采用:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM