簡體   English   中英

應用程序可以為Spotlight提供一個鈎子來搜索應用程序內的內容嗎?

[英]Can apps provide a hook for Spotlight to search content within the app?

示例:應用程序包含消息。 用戶使用消息中的字符串搜索聚光燈。 Spotlight找到該應用。

我聽說聚光燈可以搜索應用內容。 但是如何將它提供給iOS上的Spotlight?

根據Core Data Spotlight集成編程指南 ,您所需的功能不適用於iOS,僅適用於Mac OS X.

現在可以從iOS9開始實現。

Apple發布了CoreSpotlight SDK(WWDC2015),您可以將您的應用程序集成到iOS的聚光燈下,並可以進行內容搜索。

還有其他可能的途徑可以將不同的用戶活動實際集成到您的應用中,即使您的應用未安裝在設備上,也可以搜索內容。

如果您的應用程序是一個處理pdf的應用程序,例如,如果用戶在他的設備上搜索pdf,那么您的應用程序可以作為他可以用來閱讀pdf的應用程序出現在聚光燈首選項中,即使您的應用程序未安裝在用戶的設備。

考慮到您的示例,現在可能的是,如果您在聚光燈下搜索消息字符串,聚光燈可以打開您的應用程序,您可以讓用戶實際導航以查找應用程序內的確切消息。

添加以下鏈接:您可以找到實施細節。

https://developer.apple.com/library/prerelease/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS9.html#//apple_ref/doc/uid/TP40016198-SW3

-Tejas

以下是通過新的Search API將您的應用內容添加到Spotlight的示例。 這可以在iOS9上使用XCode 7獲得。

CSSearchableItemAttributeSet * attributes = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeImage]; //Or whatever type
attributes.contentDescription = @"This is my content description.";
attributes.displayName = @"Display Name";
attributes.keywords = @["Stuff","Widget"];
attributes.subject = @"Subject";
attributes.title = @"Title";

CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:someUniqueId domainIdentifier:@"SomeGroupName" attributeSet:attributes];

[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler:nil];

當用戶在聚光燈下選擇項目時,使用以下方法:

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

在你的AppDelegate中將被調用。 檢查userActivity對象中的userInfo字典,並將用戶發送到適當的屏幕。

我創建了一個示例項目來集成corespotlgiht功能。 它適用於iOS 9,需要Xcode 7 beta 2才能構建。 你可以試試它是否有幫助。 https://github.com/majain/iPhoneCoreDataRecipes

視頻鏈接為: https//youtu.be/Renm1xLDIFc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM