I am working on a project where I want to make Push notifications work, on Parse-Server (Heroku), with an iOS app.
This is the code I use on the server side to generate a 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;
}
});
On the iOS app side, I receive the notification, but I would like to tweak it to my taste, if possible.
Here is the relevant swift code where I can see the notification coming:
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print(#function)
print("NN = \(notification.description)")
}
And finally, this is what I can see in the Xcode debugging console, when the notification arrives:
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>>>
Obviously, it is working up to a point. But I can see fields in the incoming notification that I do not control. Namely: title, subtitle, summaryArgument, categoryIdentifier ...... In fact only "body" is what I have set on the server side.
Therefore my question is: how can I set all those fields the way I wish.
I have already tried something like this:
data: {
title: "MyOwnTitle",
alert: "ABCXYZ"
}
But without success.
Furthermore, by using something like:
data: {
alert: "ABCXYZ",
content_available: 1,
push_type: "background",
category: "S3x"
}
I can see the following in the Xcode debugging console, when the notification arrives:
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>>>
Where it appears that the "ABCXYZ" part is transferred as well as the category (S3x), but the rest (content_available,push_type) seems to be ignored.