Apple documentation on CoreSpotlight टूट जाता है:
एक CSSearchableItemAttributeSet वस्तु बना सकते हैं और गुण है कि आइटम आप अनुक्रमित करना चाहते वर्णन निर्दिष्ट करें।
आइटम का प्रतिनिधित्व करने के लिए एक CSSearchableItem ऑब्जेक्ट बनाएं। एक CSSearchableItem ऑब्जेक्ट में एक अद्वितीय पहचानकर्ता है जो आपको बाद में का संदर्भ देता है।
यदि आवश्यक हो, तो एक डोमेन पहचानकर्ता निर्दिष्ट करें ताकि आप एक साथ कई आइटम एकत्र कर सकें और उन्हें समूह के रूप में प्रबंधित कर सकें।
खोजने योग्य आइटम के साथ विशेषता सेट को संबद्ध करें।
सूचकांक में खोजने योग्य आइटम जोड़ें।
यहाँ एक त्वरित उदाहरण मुझे लगता है कि दिखाता है कि कैसे करने के लिए सूचकांक एक साधारण नोट वर्ग है:
class Note {
var title: String
var description: String
var image: UIImage?
init(title: String, description: String) {
self.title = title
self.description = description
}
}
फिर कुछ अन्य समारोह में, अपने नोट्स बनाने के लिए, प्रत्येक नोट के लिए एक CSSearchableItemAttributeSet
बनाने के लिए, बनाने के एक अद्वितीय CSSearchableItem
विशेषता सेट, और सूचकांक खोज योग्य आइटम के संग्रह से:
import CoreSpotlight
import MobileCoreServices
// ...
// Build your Notes data source to index
var notes = [Note]()
notes.append(Note(title: "Grocery List", description: "Buy milk, eggs"))
notes.append(Note(title: "Reminder", description: "Soccer practice at 3"))
let parkingReminder = Note(title: "Reminder", description: "Soccer practice at 3")
parkingReminder.image = UIImage(named: "parkingReminder")
notes.append(parkingReminder)
// The array of items that will be indexed by CoreSpotlight
var searchableItems = [CSSearchableItem]()
for note in notes {
// create an attribute set of type Text, since our reminders are text
let searchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String)
// If we have an image, add it to the attribute set
if let image = note.image {
searchableItemAttributeSet.thumbnailData = UIImagePNGRepresentation(image)
// you can also use thumbnailURL if your image is coming from a server or the bundle
// searchableItemAttributeSet.thumbnailURL = NSBundle.mainBundle().URLForResource("image", withExtension: "jpg")
}
// set the properties on the item to index
searchableItemAttributeSet.title = note.title
searchableItemAttributeSet.contentDescription = note.description
// Build your keywords
// In this case, I'm tokenizing the title of the note by a space and using the values returned as the keywords
searchableItemAttributeSet.keywords = note.title.componentsSeparatedByString(" ")
// create the searchable item
let searchableItem = CSSearchableItem(uniqueIdentifier: "com.mygreatapp.notes" + ".\(note.title)", domainIdentifier: "notes", attributeSet: searchableItemAttributeSet)
}
// Add our array of searchable items to the Spotlight index
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems(searchableItems) { (error) in
if let error = error {
// handle failure
print(error)
}
}
यह उदाहरण मधुमक्खी है n AppCoda's How To Use Core Spotlight Framework in iOS 9 गाइड से अनुकूलित।
तो आपका डेटा संदेश है? वर्तमान में आप किस मूल्य को मूल्य निर्धारित कर रहे हैं? विषय या पाठ सामग्री? – Wain
आप अपने ऐप में .txt फ़ाइल को सिर्फ डीप्लंक क्यों नहीं कर सकते हैं। मुझे पता है कि यह आपके मामले के लिए एक हैक होगा, लेकिन आपकी समस्या भी हल कर सकता है। डिप्लिंक करने के लिए, अद्वितीय पहचानकर्ता सेट करें और इसे '- (BOOL) एप्लिकेशन में प्राप्त करें: (यूआईएप्लिकेशंस *) एप्लिकेशन जारी रखें उपयोगकर्ता निष्क्रियता: (nonnull NSUserActivity *) उपयोगकर्ता सक्रियता बहाली हैंडलर: (nonnull शून्य (^) (NSArray * _Nullable)) बहाली हैंडलर {} 'में AppDelegate.m –
@Wain, डेटा उपयोगकर्ता द्वारा संग्रहीत किया जाता है, इसलिए सिद्धांत में यह कोई भी पाठ हो सकता है, इसकी सामान्य लंबाई लगभग 5000 वर्ण है, हालांकि यह कोई लंबाई हो सकती है। मैंने शीर्षक और थंबनेल यूआरएल सेट किया है, अगर आइटम वेब से निकलता है तो मैं सामग्री स्रोत भी सेट करता हूं। –