标签: corespotlight

是否有针对corepotlight搜索功能的示例代码 - iOS 9 API?

是否有针对corepotlight搜索功能的示例代码 - iOS 9 API?真的很感激,如果可以查看示例代码来实现/测试.

objective-c ios9 xcode7 corespotlight

23
推荐指数
4
解决办法
1万
查看次数

continueUserActivity未从搜索关闭应用程序调用

我正在尝试使用核心聚光灯从聚光灯搜索结果中打开视图控制器.

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler 
{

if(self.window.rootViewController){
    [self.window.rootViewController restoreUserActivityState:userActivity];
}

return YES;
}
Run Code Online (Sandbox Code Playgroud)

当应用程序已经在后台运行时,这似乎有效,但是当它关​​闭时我点击聚光灯搜索结果似乎没有调用此方法,我得到的行为是我的应用程序只是在主界面中启动.

当我的应用程序关闭时,你有什么建议让它工作吗?有没有办法调试正在发生的事情(因为我需要运行应用程序以连接调试器我不知道如何从搜索结果模拟应用程序打开)?

xcode user-activity ios ios9 corespotlight

17
推荐指数
8
解决办法
7426
查看次数

使用Core Data时更新Spotlight搜索索引?

我有一个Core Spotlight用于索引应用内容的应用.该应用程序还使用Core Data,并在创建NSManagedObject对象的详细信息时使用,CSSearchableItem然后添加到Spotlight Search Index.

事情是,我的印象是,没有方向参考下NSManagedObject和CSSearchableItem,所以当项目被添加到索引,它只是复制的细节.

以下是将项添加到索引的示例.

//Spotlight Index Search
// Create an attribute set to describe an item.

    let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeData as String)

// Add metadata that supplies details about the item.

    attributeSet.title = "\(object.title)"
    attributeSet.contentDescription = "\(object.description)"

// Create an item with a unique identifier, a domain identifier, and the attribute set you created earlier.
    let item = CSSearchableItem(uniqueIdentifier: "1", domainIdentifier: "ObjectType", …
Run Code Online (Sandbox Code Playgroud)

core-data ios swift corespotlight

13
推荐指数
2
解决办法
1627
查看次数

iOS 9中Core Spotlight CSSearchableIndex中的项目数量(CSSearchableItem)是否有限制?

我有大约110,000个条目(CSSearchableItem),我想索引到iOS 9 Spotlight搜索结果.但是我只设法显示了大约30,000个项目.当我进行搜索时,其余部分从未编入索引/出现.所以我不确定应用程序是否有限制将其条目索引到系统中.

谢谢.

ios ios9 corespotlight

13
推荐指数
1
解决办法
955
查看次数

CoreSpotlight缩略图图像未显示在Spotlight搜索上

我试图在Core Spotlight的帮助下搜索我的应用程序内容.一切都很好,标题和描述来了,但没有缩略图.

这是我正在尝试的:

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

attributeSet.title = @"My First Spotlight Search";
attributeSet.contentDescription = @"This is my first spotlight Search";

attributeSet.keywords = [NSArray arrayWithObjects:@"Hello", @"Welcome",@"Spotlight", nil];

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

CSSearchableItem *item = [[CSSearchableItem alloc]initWithUniqueIdentifier:@"com.deeplink" domainIdentifier:@"spotlight.sample" attributeSet:attributeSet];

[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler: ^(NSError * __nullable error) {
    if (!error)
        NSLog(@"Search item indexed");
}];
Run Code Online (Sandbox Code Playgroud)

objective-c ios ios9 corespotlight

8
推荐指数
1
解决办法
3232
查看次数

在NSUserActivity上CSSearchableIttributeSet应该使用哪些属性?

我在网站上添加了Web Markup,因此当用户在iOS 9中搜索时,项目将显示在Spotlight搜索结果中.用户可以浏览应用程序中的相同项目,因此我想创建NSUserActivity在用户浏览项目时链接到Web内容的对象.

现在,NSUserActivity有一个contentAttributeSet属性我将用于将缩略图照片附加到活动.CSSearchableItemAttributeSet有一些属性NSUserActivity也有,所以我不确定我应该实现哪一个,或者我应该为两者指定相同的数据.难道我设置title的NSUserActivity,以及在title上CSSearchableItemAttributeSet,或只有一个或其他?同样keywords是两者的财产.

NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@“com.domain.appname-something"];
activity.title = @“My Title";
activity.keywords = [NSSet setWithArray:@[@“one", @“two", @“three"]];
activity.userInfo = @{@“id": @“12345"};
activity.requiredUserInfoKeys = [NSSet setWithArray:@[@“id"]];
activity.eligibleForSearch = YES;
activity.eligibleForPublicIndexing = YES;
activity.webpageURL = [NSURL URLWithString:@"https://someurl.com"];

//QUESTION: Do I need to duplicate title and keywords here:
CSSearchableItemAttributeSet *contentAttributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeImage];
contentAttributeSet.title = activity.title;
contentAttributeSet.displayName = …
Run Code Online (Sandbox Code Playgroud)

ios corespotlight ios-searchapi nsuseractivity

7
推荐指数
1
解决办法
933
查看次数

CSSearchableItemAttributeSet搜索结果的contentType

我正在构建一个使用CSSearchableItemAttributeSetwith 的应用程序,NSUserActivity以便将项目添加到Spotlight搜索索引中.我正在索引的项目是表情符号,它由表情符号字符本身,描述和显示表情符号的图像组成.我正在创建一个活动,然后将项目属性集绑定到它,这允许我指定缩略图图像.

我的问题是,在这种情况下,内容类型应该是CSSearchableItemAttributeSet什么?

我最初认为它应该是kUTTypeImage.但是图像不是被索引的项目,而是表情符号字符.图像仅提供补充信息.

NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@“com.domain.appname-something"];
activity.title = @“<emoji here>";

CSSearchableItemAttributeSet *contentAttributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeImage]; //QUESTION: What’s the appropriate contentType?
contentAttributeSet.contentDescription = @"<emoji description here>";
contentAttributeSet.thumbnailData = [self generateEmojiImage];

activity.contentAttributeSet = contentAttributeSet;
Run Code Online (Sandbox Code Playgroud)

ios corespotlight ios-searchapi

6
推荐指数
0
解决办法
412
查看次数

如何在核心聚焦中正确批量索引

我开始使用Core Spotlight来索引我的应用中的项目.正如我想的那样,应用程序崩溃在我的设备上,但不是模拟器,因为我有2000多个项目要索引.我注意到,当我向我的物品添加大约427个物品时,我开始收到记忆警告NSMutableArray,并且当它到达540个物品时完全崩溃.

我知道batch这些索引的能力,我可以看到Apple在他们的网站上提供的代码Apple - 索引应用程序内容 - 使用高级功能.但是,我不确定如何实现这一点.

有人可以添加一些代码或指出我正确的方向来完成这个?

更新#1(2016/06/21)

我试图索引的项目大约有2000多个名字,包括我公司的电话号码,电子邮件,标题和部门信息.我有一个内置的文件,但我也定期下载文件以获取最新信息.我将数据保存为plist,而不是CoreData.下载文件后,我首先删除当前索引的所有内容然后添加所有项目,然后启动索引.从服务器我无法确定数据是否已更改.

我的目标是一次索引大约200-400个项目,直到所有项目都被编入索引.下面是我目前如何在没有批处理的情况下编制索引.

- (void)setupCoreSpotlightSearchFor:(NSString *)fileName {
        if ([fileName isEqual:kPlistFileNameEmployee]) {
            NSFileManager *fileManager = [NSFileManager defaultManager];
            NSURL *downloadFileUrl = kDirectoryEmployeeListDownload;

            if ([fileManager fileExistsAtPath:[downloadFileUrl path]]) {
                NSArray *dataArray = nil;
                NSError *error = nil;
                dataArray = [NSArray arrayPropertyListWithURL:downloadFileUrl error:&error];
                if (!error && dataArray) {
                    NSMutableArray *items = nil;
                    int counter = 0;
                    for (NSDictionary *person in dataArray) {
                        NSNumberFormatter *f = [[NSNumberFormatter alloc] …
Run Code Online (Sandbox Code Playgroud)

objective-c ios corespotlight

6
推荐指数
1
解决办法
508
查看次数

6
推荐指数
1
解决办法
1436
查看次数

如何使用CSCus​​tomAttributeKey从Spotlight获取自定义值

我试图从Core Spotlight获取一些数据,我使用自定义属性键存储.在macOS和iOS上测试过,结果总是一样的.

我的考试班:

import CoreSpotlight

class SpotlightSearch {
  let domainId = "com.company.some"
  let originalDataKeyName: String

  init() {
    self.originalDataKeyName = domainId.replacingOccurrences(of: ".", with: "_") + "_originalData"
  }

  func addToIndex(title: String, content: String) {
    guard let originalDataKey = CSCustomAttributeKey(keyName: originalDataKeyName, searchable: false, searchableByDefault: false, unique: false, multiValued: false)

      else { return }

    let uniqueId = "MyUniqueId" + title
    let originalContent = NSString(string: content)

    let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String)
    attributeSet.title = title
    attributeSet.setValue(originalContent, forCustomKey: originalDataKey)
    let item = CSSearchableItem(uniqueIdentifier: uniqueId, domainIdentifier: …
Run Code Online (Sandbox Code Playgroud)

macos ios swift corespotlight

6
推荐指数
1
解决办法
328
查看次数