重启应用程序后,Swift 3dTouch Quick Action崩溃

时间:2017-07-31 14:33:27

标签: swift crash quickaction

我在实施3D Touch Quick操作时遇到问题。该操作应在mapview上为用户的位置设置注释。当应用程序已经运行时,它可以正常工作。但如果我杀了应用程序再试一次,它就会崩溃。

的AppDelegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    //shortcut Item


    let shortcut1 = UIMutableApplicationShortcutItem(type: "markLocation", localizedTitle: NSLocalizedString("Mark my location", comment: "Shortcut mark location"), localizedSubtitle: "", icon: UIApplicationShortcutIcon(type: .markLocation), userInfo: nil)



    application.shortcutItems = [shortcut1]


    return true
}
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    switch shortcutItem.type {
    case "markLocation":
        mapVC.addNewPin()
    default:
        print("")
    }


}

MapViewController(mapVC):

func addNewPin() {


    if lastAnnotation != nil {
        let alertController = UIAlertController(title: NSLocalizedString("Annotation already dropped", comment: "Error Message"), message: NSLocalizedString("There is an annotation on screen. Try dragging it if you want to change its location!", comment: "Eror Message"), preferredStyle: .alert)
        let alertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.destructive) { alert in
            alertController.dismiss(animated: true, completion: nil)
        }
        alertController.addAction(alertAction)
        present(alertController, animated: true, completion: nil)

    } else {
        let location = LocationAnnotation(coordinate: mapView.userLocation.coordinate, title: NSLocalizedString("To explore", comment: "Annotation Title"), subtitle: " ")

        mapView.addAnnotation(location)
        lastAnnotation = location
    }
}

0 个答案:

没有答案