由于意外崩溃,3D Touch快捷方式无效

Ril*_*Dev 9 ios swift 3dtouch

我正在尝试将3D Touch快捷方式添加到应用程序中,我已经设法在主屏幕上的应用程序图标上使用3DTouch时显示快捷方式; 但是当使用快捷方式时,应用程序在加载时崩溃,我不确定为什么.

我已设法让应用程序加载书签快捷方式,但它没有启动BookmarksViewController,它只是加载InitialViewController.

应用程序嵌入在每个选项卡的a UITabBarController和a UINavigationController中.我试图加载的两个视图控制器都在不同的选项卡中,但导航控制器堆栈中的第一个视图.

有谁知道我哪里出错了?

info.plist文件

在此输入图像描述

App代表

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)
}

}
Run Code Online (Sandbox Code Playgroud)

故事板ID

这些是View Controllers的StoryboardID.

在此输入图像描述 在此输入图像描述

nul*_*ull 5

我想你忘记了com.appName.Bookmark中的's'

在此输入图像描述

或者您需要从书签中删除's':

enum ShortcutItemType: String {

case Bookmarks
case Favourites
Run Code Online (Sandbox Code Playgroud)