【发布时间】:2020-06-14 12:20:14
【问题描述】:
我正在开发一个项目,我希望在 Parse-Server (Heroku) 上使用 iOS 应用程序来实现推送通知。
这是我在服务器端用来生成 PUSH 的代码:
const pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('deviceType', 'ios');
Parse.Push.send({
where: pushQuery, // Set our Installation query
data: {alert: "ABCXYZ"}
}, {
useMasterKey: true,
success: function() {},
error: function(error) {
throw "Got an error " + error.code + " : " + error.message;
}
});
在 iOS 应用端,我收到了通知,但如果可能的话,我想根据自己的喜好对其进行调整。
这是相关的 swift 代码,我可以在其中看到通知:
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print(#function)
print("NN = \(notification.description)")
}
最后,当通知到达时,我可以在 Xcode 调试控制台中看到:
userNotificationCenter(_:willPresent:withCompletionHandler:)
NN = <UNNotification: 0x2....; date: 2020-03-02 06:51:39 +0000,
request: <UNNotificationRequest: 0x28....3e0; identifier: 0C....AF3,
content: <UNNotificationContent: 0x28....6c0; title: (null), subtitle: (null),
body: ABCXYZ, summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: ,
launchImageName: , threadIdentifier: , attachments: (
), badge: (null), sound: (null),,
trigger: <UNPushNotificationTrigger: 0x28...0;
contentAvailable: NO, mutableContent: NO>>>
显然,它正在发挥作用。但我可以在传入通知中看到我无法控制的字段。即:title、subtitle、summaryArgument、categoryIdentifier……其实只有“body”是我在服务器端设置的。
因此我的问题是:如何按照自己的方式设置所有这些字段。
我已经尝试过这样的事情:
data: {
title: "MyOwnTitle",
alert: "ABCXYZ"
}
但没有成功。
此外,通过使用类似的东西:
data: {
alert: "ABCXYZ",
content_available: 1,
push_type: "background",
category: "S3x"
}
当通知到达时,我可以在 Xcode 调试控制台中看到以下内容:
userNotificationCenter(_:willPresent:withCompletionHandler:)
NN = <UNNotification: 0x28...; date: 2020-03-03 ...,
request: <UNNotificationRequest: 0x2..;
identifier: BF...EE, content: <UNNotificationContent: 0x28..;
title: (null), subtitle: (null), body: ABCXYZ,
summaryArgument: , summaryArgumentCount: 0,
categoryIdentifier: S3x, launchImageName: ,
threadIdentifier: , attachments: (
), badge: (null), sound: (null),,
trigger: <UNPushNotificationTrigger: 0x28..;
contentAvailable: NO, mutableContent: NO>>>
似乎“ABCXYZ”部分和类别 (S3x) 一样被转移,但其余部分 (content_available,push_type) 似乎被忽略了。
【问题讨论】:
标签: swift apple-push-notifications parse-server payload heroku-api