3D Touch无法正常工作

时间:2017-09-19 19:26:47

标签: ios swift 3dtouch

我正在尝试将3dtouch项添加到我的应用图标中。这是我的代码:

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
     if shortcutItem.type == "com.eDidaar.eDidaar.addEvent"{
       let sb = UIStoryboard(name: "Main", bundle: nil)
        let addEventVC = sb.instantiateViewController(withIdentifier: "addEvent") as! ADDEvent
        if let navigationController = window?.rootViewController as? UINavigationController {
            navigationController.pushViewController(addEventVC, animated: true)
        }


}

但启动应用程序时不会出现3d touch 我做错了什么

1 个答案:

答案 0 :(得分:0)

我将我的代码更改为此并且工作正常:

 func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {

    if shortcutItem.type == "com.eDidaar.addEvent" {
        let sb = UIStoryboard (name: "Main", bundle: nil)
        let addEventVC = sb.instantiateViewController(withIdentifier: "addEvent")
        let root = UIApplication.shared.keyWindow?.rootViewController
        root?.present(addEventVC, animated: false, completion: { () -> Void in
            completionHandler(true)
    })
}

}