我正在尝试为一个应用程序添加3D Touch快捷方式。当我在主屏幕上使用3DTouch来打开应用程序时,快捷方式会出现;然而,当我使用快捷方式时,应用程序会在加载时崩溃,我不确定原因。
我已经成功让书签快捷方式加载应用程序,但它没有启动BookmarksViewController,只加载了InitialViewController。
该应用程序嵌入在UITabBarController中,并且每个标签都有UINavigationController。我尝试加载的两个视图控制器位于不同的标签中,但是都是导航控制器堆栈中的第一个视图。
有人知道我错在哪里吗?
info.plist文件
我已经成功让书签快捷方式加载应用程序,但它没有启动BookmarksViewController,只加载了InitialViewController。
该应用程序嵌入在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)
}
}
故事板标识符
这些是视图控制器的故事板标识符。