【发布时间】:2021-07-09 11:12:58
【问题描述】:
我正在尝试在通知横幅中显示消息预览,当前显示标题,并希望显示“文本”,但找不到任何相关信息..
有效负载格式
["badge": 1, "alert": {
body = {
Body = {
FromInside = 1;
MessageId = "123456";
Read = 0;
Status = 0;
Text = Hi, hows it going?;
Timestamp = "2021-07-09T08:37:10.5020307Z";
};
PHONE = 07123456789;
CODE = 123456;
"_id" = 000000000000000000000000;
};
time = "7/9/2021 8:37:10 AM";
title = "New message";
}, "sound": default]
用户通知中心
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
let aps = userInfo["aps"] as? [String: Any]
let alert = aps!["alert"] as? [String: Any]
let messageBody = alert!["body"] as? [String: Any]
if UIApplication.shared.applicationState == .background || UIApplication.shared.applicationState == .inactive {
// let body = messageBody!["Body"] as? [String: Any] ?? nil
// let text = body!["Text"] as? String ?? ""
UIApplication.shared.applicationIconBadgeNumber = 0
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "newMessage"), object: nil, userInfo:messageBody)
}
completionHandler()
}
【问题讨论】:
-
到底是什么问题?通知横幅显示“新消息”作为其标题,但您希望它显示其他文本?您能否包含您要发送 APNS 端点的原始 JSON?
标签: swift xcode apple-push-notifications