Can I send an APN Alert Dictionary to both iOS 7 and iOS 8? - ios7

With iOS 8, there came the ability to send an the 'alert' key in the APN dictionary as either a string containing the alert text or a dictionary with the alert text in its 'body' key. See Apple docs. In iOS 7, the 'alert' key had to be a string containing the alert text.
My question is: If I want to take advantage of iOS 8 features in the 'alert' dictionary when sending remote notifications (specifically the 'title' key for the Apple Watch), will it continue to work with iOS 7? That is, is APNS aware that a device is running iOS 7 or 8 and send it the appropriate data? Or does my server have to know the device is running iOS 7 and send it a payload with an 'alert' string while sending devices running iOS 8 an 'alert' dictionary?
Does that make sense? Thanks!

It works. Tested with following payload on iOS 7.1.2:
{
"aps":{
"alert": {
"body": "alert body",
"title": "alert title"
},
"sound": "default",
"badge": 1
}
}
(Btw. I don't see any notice about being iOS8-only in the doc.)

Related

Can I modify expo push notification title/body before showing the notification?

I'm using expo notification service.
I would like to send keys from backend, e.g.
{
title: "TITLE_KEY",
body: "BODY_KEY"
}
then translate it when it comes on the mobile side (based on the key), before showing it, so user would not see the key on notification, just the translated text...
So the question is how could I modify notification before showing it to the user?

Group notifications with Expo

I have a react native messaging app done with Expo. I got notifications to work, but the problem is that each message is a separate notification.
I would like to group notifications sent by the same person. Currently, I have:
[Notification]
John - Hey, how are you?
[Notification]
John - Long time no see!
and I would like them to merge as a single one when the second message is received, like this:
[Notification]
John |
Hey, how are you?
Long time to see!
I might be missing something because I cannot find anyone else wondering about such a common functionality.
The code I use to send notifications from my backend (python):
headers = {
'Accept': 'application/json',
'Accept-encoding': 'gzip, deflate',
'Content-Type': 'application/json',
}
session.post(
"https://exp.host/--/api/v2/push/send",
json = {
"to": expo_token,
"title": username,
"body": message_content,
},
headers=headers
)
In iOS you should use apns-collapse-id
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
An identifier you use to coalesce multiple notifications into a single
notification for the user. Typically, each notification request causes
a new notification to be displayed on the user’s device. When sending
the same notification more than once, use the same value in this
header to coalesce the requests. The value of this key must not exceed
64 bytes.
Update
For using collapse feature, you can use for Notifications other service. Which supports collapse and react native - for example
https://documentation.onesignal.com/docs/how-notifications-work#section-notification-collapsing
It seems like you can not control how notifications group in Expo app now, but I noticed that on IOS they are being grouped together automatically, while on Android you need to set notification.androidMode to collapse.
Take a look at current documentation: https://docs.expo.dev/versions/latest/config/app/#androidmode
app.json
Path: notification.androidMode
Type: enum
Show each push notification individually (default) or collapse into one (collapse).
All your messages will still be separate notifications, but at least they will collapse into one (stack).
That will only work in standalone app, nor in Expo Go.

Change sound in expo.sendPushNotificationsAsync

I want to play some other sound when hitting any notification in my expo app from node server.I can't find any other sound than 'default'.Is there any other option I can use to play some other sound other than the default one on notifications in expo.My nodeJS code is below:
const receipts = expo.sendPushNotificationsAsync([
{
to: userObj.pushToken,
sound: 'default',
body: notification,
data: { withSome: notification },
priority: 'high',
},
]);
I looked up in the Message Format section of the docs and found this :
A sound to play when the recipient receives this notification. Specify
"default" to play the device's default notification sound, or omit this
field to play no sound.
Note that on apps that target Android 8.0+ (if using `expo build`, built
in June 2018 or later), this setting will have no effect on Android.
Instead, use `channelId` and a channel with the desired setting.
sound?: 'default' | null,
Looks like it is not possible to change sound through app.

GCM 3.0 - send notification paylod to iOS and data payload to Android?

I would like to use the notification payload for iOS notifications (not Android), and the data payload for Android.
Is this possible? I am worried by using the notification payload for iOS, the Android notification will ben generated automatically.
With a single topic, if you want to deliver a push via notification payload on iOS, but via data payload on Android, you can't!
For example, if you have a topic called "awesome_news" you should split this into two topics: "awesome_news_ios" and "awesome_news_android"

How does FB messenger removes push notification from iOS app when I see the message on FB Desktop?

Whenever I get a notification about a message on my iPhone from Facebook and I reply to that message from Facebook website, that push notification goes away from my iPhone home screen. How is Facebook doing that? I know push notification don't have delivery confirmation mechanism in iOS. Here in this scenario Facebook knows I have read the message so are they pushing something to their app to remove notification? Even if they're sending a message to their app that I have read this message how is app removing that notification when I don't have background app refresh enabled for FB messenger or FB iOS app.
What you do is after you've sent the notification you want to remove, you send a notification with the message="" and badge=0. I just tested this in a node js application and it removed the previous notification like you are saying.
After testing myself as following, the answer by SnoApps is correct. The tests I described below assumes the account on iPhone is A.
Test 1:
- Send message 1 from B to A => notification shown on iPhone
- A reads message 1 on desktop => notification on iPhone is gone
Test 2:
- Send message 1 from B to A => notification shown on iPhone
- Send message 2 from C to A => another notification shown
- A reads message 1 on desktop => both notifications still exist
- A reads message 2 on desktop => both notifications gone
And I tested WhatsApp and WeChat, all of them using similar way to do this, which is when server count of unread messages becomes 0, send a silent notification with an empty body and badge 0 to iPhone. the iOS will clear the banners for you.