我想3D觸控快捷鍵添加到應用程序,我已成功有捷徑出現;但是,當使用快捷方式時,應用程序在加載時崩潰,我不確定原因。3D觸控快捷鍵不起作用因意外碰撞
我已經設法讓應用程序加載書籤快捷方式,但它不啓動BookmarksViewController
,它只是加載InitialViewController
。
該應用程序嵌入在每個Tab的UITabBarController
和UINavigationController
之內。我試圖加載的兩個視圖控制器都在不同的選項卡中,但導航控制器堆棧中的第一個視圖。
有沒有人知道我要去哪裏錯了?
Info.plist文件
應用代表
enum ShortcutItemType: String {
case Bookmarks
case Favourites
init?(shortcutItem: UIApplicationShortcutItem) {
guard let last = shortcutItem.type.componentsSeparatedByString(".").last else { return nil }
self.init(rawValue: last)
}
var type: String {
return NSBundle.mainBundle().bundleIdentifier! + ".\(self.rawValue)"
}
}
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
handleShortcutItem(shortcutItem)
}
return true
}
private func handleShortcutItem(shortcutItem: UIApplicationShortcutItem) {
if let rootViewController = window?.rootViewController, let shortcutItemType = ShortcutItemType(shortcutItem: shortcutItem) {
let sb = UIStoryboard(name: "main", bundle: nil)
let favouritesVC = sb.instantiateViewControllerWithIdentifier("FavouritesVC") as! FavouritesTableViewController
let bookmarksVC = sb.instantiateViewControllerWithIdentifier("BookmarksVC") as! BookmarksNotesViewController
switch shortcutItemType {
case .Bookmarks:
rootViewController.presentViewController(bookmarksVC, animated: true, completion: nil)
break
case .Favourites:
rootViewController.presentViewController(favouritesVC, animated: true, completion: nil)
break
}
}
}
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
handleShortcutItem(shortcutItem)
}
}
故事板ID
這些都是StoryboardID的視圖控制器。
我確實做到了同樣的事情,與我的項目,檢查你的代碼後,唯一的區別是,我「返回false」處理快捷方式項後appDidFinishLaunchWithOption方法,以防止它執行performActionForShortcut項目方法。你可以試試。 – Surely
你能提供崩潰的堆棧跟蹤嗎? –