Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift:单击“推送通知”操作按钮时写入文本字段并进行处理_Ios_Swift_Xcode_Unusernotificationcenter - Fatal编程技术网

Ios Swift:单击“推送通知”操作按钮时写入文本字段并进行处理

Ios Swift:单击“推送通知”操作按钮时写入文本字段并进行处理,ios,swift,xcode,unusernotificationcenter,Ios,Swift,Xcode,Unusernotificationcenter,我使用的是Xcode 9.4.1(9F2000)和Swift 我在AppDelegate中有此代码: func showPushButtons(){ let replyAction = UNNotificationAction( identifier: "reply.action", title: "Reply to this message", options: []) let pushNotificationButtons =

我使用的是
Xcode 9.4.1(9F2000)
Swift

我在
AppDelegate
中有此代码:

func showPushButtons(){
    let replyAction = UNNotificationAction(
        identifier: "reply.action",
        title: "Reply to this message",
        options: [])

    let pushNotificationButtons = UNNotificationCategory(
        identifier: "allreply.action",
        actions: [replyAction],
        intentIdentifiers: [],
        options: [])

    UNUserNotificationCenter.current().setNotificationCategories([pushNotificationButtons])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    let action = response.actionIdentifier
    let request = response.notification.request
    let content = response.notification.request.content.userInfo

    if action == "reply.action"{
        print("Reply button clicked")

        completionHandler()
    }
}
这使得:

收到推送通知时,将显示一个名为“回复此消息”的操作按钮

当前,单击按钮时,console会打印单击的回复按钮

我想做的是:

如果我点击按钮,就会出现一个文本字段和键盘(如消息应用程序中所述)。在编写一些文本并提交/发送后,我想在
AppDelegate
中接收此消息以处理它

你知道怎么做吗?有什么提示吗?

此代码现在可以工作了:

func showPushButtons(){
    let replyAction = UNTextInputNotificationAction(
        identifier: "reply.action",
        title: "Reply on message",
        textInputButtonTitle: "Send",
        textInputPlaceholder: "Input text here")

    let pushNotificationButtons = UNNotificationCategory(
        identifier: "allreply.action",
        actions: [replyAction],
        intentIdentifiers: [],
        options: [])

    UNUserNotificationCenter.current().setNotificationCategories([pushNotificationButtons])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    if  response.actionIdentifier  ==  "reply.action" {
        if let textResponse =  response as? UNTextInputNotificationResponse {
            let sendText =  textResponse.userText
            print("Received text message: \(sendText)")
        }
    }
    completionHandler()
}
功能:如果您收到带有
“类别”的推送通知:“allreply.action”
,并在其上进行强制点击,则会出现文本字段和键盘,您可以使用
打印(“接收到的文本消息:\(sendText)”)
进行打印

不要忘记从
did使用选项完成启动调用
showPushButtons()
,并准备应用程序以接收(远程)推送通知。

此代码现在可以工作:

func showPushButtons(){
    let replyAction = UNTextInputNotificationAction(
        identifier: "reply.action",
        title: "Reply on message",
        textInputButtonTitle: "Send",
        textInputPlaceholder: "Input text here")

    let pushNotificationButtons = UNNotificationCategory(
        identifier: "allreply.action",
        actions: [replyAction],
        intentIdentifiers: [],
        options: [])

    UNUserNotificationCenter.current().setNotificationCategories([pushNotificationButtons])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    if  response.actionIdentifier  ==  "reply.action" {
        if let textResponse =  response as? UNTextInputNotificationResponse {
            let sendText =  textResponse.userText
            print("Received text message: \(sendText)")
        }
    }
    completionHandler()
}
功能:如果您收到带有
“类别”的推送通知:“allreply.action”
,并在其上进行强制点击,则会出现文本字段和键盘,您可以使用
打印(“接收到的文本消息:\(sendText)”)
进行打印


不要忘记从
did使用选项完成启动时调用
showPushButtons()
,并准备好应用程序以接收(远程)推送通知。

将您的
replyAction
替换为以下操作:

let replyAction = UNTextInputNotificationAction(identifier: "reply.action", title: "message", options: [], textInputButtonTitle: "Send", textInputPlaceholder: "type something …")

这应该可以解决您的问题。

将您的
回复操作
替换为以下操作:

let replyAction = UNTextInputNotificationAction(identifier: "reply.action", title: "message", options: [], textInputButtonTitle: "Send", textInputPlaceholder: "type something …")

这应该可以解决您的问题。

可能重复的可能重复的任何想法为什么上面的代码在iOS 13中不工作?有什么提示吗?知道为什么上面的代码在iOS 13中不起作用吗?有什么提示吗?