【发布时间】:2018-07-17 16:28:32
【问题描述】:
我正在使用Xcode 9.4.1 (9F2000) 和Swift。
我在AppDelegate中有这个代码:
func showPushButtons(){
let replyAction = UNTextInputNotificationAction(
identifier: "reply.action",
title: "Reply to 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) {
let action = response.actionIdentifier
let request = response.notification.request
let content = response.notification.request.content.userInfo
print("\(action)\(request)\(content)")
if let aps = content["aps"] as? [String: AnyObject] {
dump(aps)
}
completionHandler()
}
它的作用:
当收到推送通知时,将显示一个文本字段并出现键盘。我可以写消息并提交。
我的问题是:我怎样才能在我的AppDelegate 中获取这个提交的消息来处理它(发送到我的服务器左右)?
使用print("\(action)\(request)\(content)"),我检查了邮件不在action、request 或content 中。
如您所见,我还检查了它是否在 aps 有效负载中,但不是。
【问题讨论】:
标签: ios swift xcode apple-push-notifications unusernotificationcenter