diff --git a/pass/AppDelegate.swift b/pass/AppDelegate.swift index a460f3b..19c7a61 100644 --- a/pass/AppDelegate.swift +++ b/pass/AppDelegate.swift @@ -18,8 +18,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. + if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem { + print(shortcutItem.type) + if shortcutItem.type == "me.mssun.pass.search" { + self.perform(#selector(postSearchNotification), with: nil, afterDelay: 0.4) + } + } return true } + + func postSearchNotification() { + NotificationCenter.default.post(Notification(name: Notification.Name("search"))) + } + + func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { + if shortcutItem.type == "me.mssun.pass.search" { + let tabBarController = self.window!.rootViewController as! UITabBarController + tabBarController.selectedIndex = 0 + let navigationController = tabBarController.selectedViewController as! UINavigationController + navigationController.popToRootViewController(animated: false) + self.perform(#selector(postSearchNotification), with: nil, afterDelay: 0.4) + } + } func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. diff --git a/pass/Info.plist b/pass/Info.plist index fe9527d..37efd74 100644 --- a/pass/Info.plist +++ b/pass/Info.plist @@ -22,6 +22,17 @@ 1 LSRequiresIPhoneOS + UIApplicationShortcutItems + + + UIApplicationShortcutItemTitle + Search + UIApplicationShortcutItemType + $(PRODUCT_BUNDLE_IDENTIFIER).search + UIApplicationShortcutItemIconType + UIApplicationShortcutIconTypeSearch + + UILaunchStoryboardName Main UIMainStoryboardFile diff --git a/pass/PasswordsViewController.swift b/pass/PasswordsViewController.swift index 9686b9c..604f7fa 100644 --- a/pass/PasswordsViewController.swift +++ b/pass/PasswordsViewController.swift @@ -64,6 +64,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData() NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordUpdatedNotification), name: NSNotification.Name(rawValue: "passwordUpdated"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordStoreErasedNotification), name: NSNotification.Name(rawValue: "passwordStoreErased"), object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnSearchNotification), name: NSNotification.Name(rawValue: "search"), object: nil) generateSections(item: passwordEntities!) tableView.delegate = self @@ -196,6 +197,10 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData() reloadTableView(data: passwordEntities!) } + + func actOnSearchNotification() { + searchController.searchBar.becomeFirstResponder() + } override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {