3D touch to search

This commit is contained in:
Bob Sun 2017-02-08 12:47:05 +08:00
parent 563156b0a4
commit 97056ab91c
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
3 changed files with 36 additions and 0 deletions

View file

@ -18,9 +18,29 @@ 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.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

View file

@ -22,6 +22,17 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemTitle</key>
<string>Search</string>
<key>UIApplicationShortcutItemType</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).search</string>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeSearch</string>
</dict>
</array>
<key>UILaunchStoryboardName</key>
<string>Main</string>
<key>UIMainStoryboardFile</key>

View file

@ -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
@ -197,6 +198,10 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
reloadTableView(data: passwordEntities!)
}
func actOnSearchNotification() {
searchController.searchBar.becomeFirstResponder()
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "showPasswordDetail" {