Push notification Swift iOS 13:点击推送通知如何打开文本字段?

Push notification Swift iOS 13:点击推送通知如何打开文本字段?,push-notification,uitextfield,ios13,xcode11.3,Push Notification,Uitextfield,Ios13,Xcode11.3,用户希望在点击推送通知时进行交互,并发送评论/回复/消息 我在AppDelegate中有以下代码: func configureNotification() { let center = UNUserNotificationCenter.current() center.requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in } cente

用户希望在点击推送通知时进行交互,并发送评论/回复/消息

我在AppDelegate中有以下代码:

     func configureNotification() {
        let center = UNUserNotificationCenter.current()

        center.requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in }

        center.delegate = notificationDelegate

        let replyAction = UNTextInputNotificationAction(identifier: replyID, title: "Add reply", options: [], textInputButtonTitle: "Send", textInputPlaceholder: "Reply here")

        let deafultCategory = UNNotificationCategory(identifier: "CustomSamplePush", actions: [replyAction], intentIdentifiers: [], options: [])
        center.setNotificationCategories(Set([deafultCategory]))

        UIApplication.shared.registerForRemoteNotifications()
    }
并处理如下操作:

 func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {

        let identifier = response.actionIdentifier
               let request = response.notification.request


        if identifier == replyID{
            let textResponse = response as! UNTextInputNotificationResponse
            let newContent = request.content.mutableCopy() as! UNMutableNotificationContent
            newContent.body = textResponse.userText
            addNotification(content: newContent, trigger: request.trigger, indentifier: request.identifier)
        }

        completionHandler()
    }


    func addNotification(content:UNNotificationContent,trigger:UNNotificationTrigger?, indentifier:String){
        let request = UNNotificationRequest(identifier: indentifier, content: content, trigger: trigger)
        UNUserNotificationCenter.current().add(request, withCompletionHandler: {
            (errorObject) in
            if let error = errorObject{
                print("Error \(error.localizedDescription) in notification \(indentifier)")
            }
        })
    }

仅供参考:此代码完全适用于iOS 11设备,但不适用于iOS 13