1
私はuserActivity.titleに何も得ていません。それはappdelegateでnilになります。これをチェックすると、ios9で動作するようになりました。私はtitleSetをattributeSet.titleに設定する必要がありますが、常にnilです。アプリデリゲートのインデックス私のアイテムIos10 swift 3 core spotlight search cantはnsuseractivityのタイトルを取得します
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String)
attributeSet.title = "ALFRESCO" //restnombre //project[0]
attributeSet.contentDescription = "\(tipocomida)"
let item = CSSearchableItem(uniqueIdentifier: "\(restid)", domainIdentifier: "com.cgcompany.restaurants", attributeSet: attributeSet)
CSSearchableIndex.default().indexSearchableItems([item]) { (error: Error?) -> Void in
if let error = error {
print("Indexing error: \(error.localizedDescription)")
} else {
print("Search item successfully indexed!")
}
}
コードへ
コード
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
// if #available(iOS 9.0, *) {
print("CALLING CONTINUE USER ACT")
if userActivity.activityType == CSSearchableItemActionType {
print("ACT TYPE IS CSSEARCHABLEITEM")
var title = "NOTITLE"
if (userActivity.title) != nil {
title = userActivity.title!
}
if let uniqueIdentifier = userActivity.userInfo?[CSSearchableItemActivityIdentifier] as? String {
print ("Calling FROM SPOTLIGHTSEARCH")
let rootViewController = self.window!.rootViewController as! UINavigationController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let restaurantdetail = mainStoryboard.instantiateViewController(withIdentifier: "restaurant_detail2") as! VCviendorest
let detailurl = "http://www.urltoget.com/iphone/\(uniqueIdentifier)/fromiOSSearch.html"
restaurantdetail.IDREST = uniqueIdentifier
restaurantdetail.NOMBRERESTAURANT = "\(title)" //userActivity.title!
restaurantdetail.DETAILURL = detailurl
rootViewController.pushViewController(restaurantdetail, animated: true)
}
}
// } else {
// Fallback on earlier versions
// }
return true
}
そんなにありがとう! –