Search code examples
iosswift3dtouch

3D Touch not working


im trying to add 3dtouch item to my app icon. here is my code:

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


}

but 3d touch doesn't appear when i launch the application what am i doing wrong


Solution

  • i changed my code to this and it worked fine:

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

    }