ios - How to continue spotlight search and show content ViewController -
i had spotlight search sorted out, problem i'm facing how show content view based on item has been press in spotlight.
my app's structure uitabvc
>uinavigationvc
>uicollectionvc
>uivc
spotlight , code shown below
// continue spotlight search func application(_ application: uiapplication, continue useractivity: nsuseractivity, restorationhandler: @escaping ([any]?) -> void) -> bool { if useractivity.activitytype == cssearchableitemactiontype { let uniqueidentifier = useractivity.userinfo?[cssearchableitemactivityidentifier] as! string let id = uniqueidentifier.components(separatedby: "_") let roottabvc = uistoryboard(name: "main", bundle: nil).instantiateviewcontroller(withidentifier: "roottabvc") as! roottabvc print(id[0], id[1], separator: " - ", terminator: "\n") // printed "craft - shovel" switch id[0] { case "craft" : let craftvc = uistoryboard(name: "main", bundle: nil).instantiateviewcontroller(withidentifier: "craftdetailvc") as! craftitemdetailvc let craftrootcollectionvc = uistoryboard(name: "main", bundle: nil).instantiateviewcontroller(withidentifier: "craftrootcollectionvc") as! craftcollectionvc let craftitemscollectionvc = uistoryboard(name: "main", bundle: nil).instantiateviewcontroller(withidentifier: "craftitemscollectionvc") as! craftitemscollectionvc // mark: - todo show vc case "character" : break case "mob" : break case "plant" : break case "recipe" : break case "thing" : break case "material" : break default: break } } return true }
even have same problem in 1 of app. surfing on internet solution, here best sample example , code along it's explanation.
func application(_ application: uiapplication, continue useractivity: nsuseractivity, restorationhandler: @escaping ([any]?) -> void) -> bool { guard useractivity.activitytype == employee.domainidentifier, let objectid = useractivity.userinfo?["id"] as? string else { return false } if let nav = window?.rootviewcontroller as? uinavigationcontroller, let listvc = nav.viewcontrollers.first as? employeelistviewcontroller, let employee = employeeservice().employeewithobjectid(objectid) { nav.poptorootviewcontroller(animated: false) let employeeviewcontroller = listvc .storyboard? .instantiateviewcontroller(withidentifier: "employeeview") as! employeeviewcontroller employeeviewcontroller.employee = employee nav.pushviewcontroller(employeeviewcontroller, animated: false) return true } return false }
Comments
Post a Comment