您需要在应用程序委托中接收快捷方式项目,然后根据您将在中定义的快捷方式类型采取适当的操作。
info.plist
.类似的东西应该可以工作,尽管它可能需要根据应用程序的确切结构或子类名称等进行修改。
应用内委托:
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
print("Opening app from 3D touch shortcut...")
completionHandler(handleShortcut(shortcutItem: shortcutItem))
}
private func handleShortcut(shortcutItem: UIApplicationShortcutItem) -> Bool {
if shortcutItem.type == "firstShortcutType" {
guard let tabBarController = self.window.rootViewController as? UITabBarController else { return false }
guard let navigationController = tabBarController.viewcontrollers[0] as? UINavigationController else { return false }
guard let tableViewController = navigationController.rootViewController as? UITableViewController else { return false }
tabBarController.selectedIndex = 0
DispatchQueue.main.asyncAfter(deadline: .now()+1, execute: {
let indexPath = IndexPath(row: 0, section: 0)
self.tableViewController.tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
})
return true
} else if shortcutItem.type == "otherShortcutType" {
} else {
return false
}
}