iOS: Is it possible to send a push to Notification Center without a sound?

1.4k Views Asked by At

On Android, I can send a silent push that gets delivered to the system tray. On iOS, I'm not sure if this is possible. I removed the alert property from aps, and I'm sending an empty string for sound. What I'm seeing is that the badge count is updated silently (which is good), but there is nothing in Notification Center. So is there a way to send a push to NC without a sound?

Note that I do not want the push to pop up on the screen (i.e. the user should not see it unless they swipe down on the screen to reveal what's been delivered. In other words, I'm trying to match the behavior on Android).

5

There are 5 best solutions below

2
elyalvarado On BEST ANSWER

The only way to achieve what you want to do will be to specify "provisional" when asking the notification permission on the device, which is supported on iOS >= 12. This makes the notifications received be completely silent and appear only on the notification center without interrupting the user. However, the user can customize this and choose to be "interrupted" by the notifications, and this permission will also prevent all other notifications from "interrupting" the user.

If you want to selectively specify some notifications to only go to the Notification Center, while others make sounds and show as notification alerts to the user, then the answer to your question is no, its not possible.

1
yangxiaoseng On

yes, apple support it, the push data format is

{
    "aps":{
        "aa":"123",
        "content-available":1
    }
}

important key is this
"content-available":1

4
Nirav Kotecha On

If you don't want sound then don't send sound param in payload.

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 1
    },
    "acme1" : "test"
}

also you can remove .alert and .sound from willPresent.. method of push in appdelegate.swift file

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
    completionHandler([.badge]) //remove .sound, .alert
}
0
Reinhard Männer On

I am not sure if I understand your question right. But if you just want to send a silent notification to iOS, wake up the app in background and let it handle the notification, this can be done, see the docs.
Essentially, you have

  • to enable the remote notifications background mode in the Signing & Capabilities tab of your target, and
  • to create a remote notification with an aps dictionary that includes only the content-available key:

    { "aps" : { "content-available" : 1 }, "key1" : "xxx", "key2" : 123 }

To receive the silent notification, the system will then wake your app in the background. It then calls your app delegate’s application(_:didReceiveRemoteNotification:fetchCompletionHandler:)

0
Parth Patoliya On

Yes just send it without sound key.If you add blank sound key then also default sound will come for sure, so not to add key for no sound.