-->

What is difference between remote notification and

2018-12-31 22:12发布

问题:

When I read Apple Docs, they mention 3 types of notification: local, remote, and silent.

Local notification can be inferred from its name, that is sent by the app locally.

However, what is the difference of the other two types?

回答1:

EDIT: While this answer is fully applicable, there are some additions (not changes) to notifications in iOS 12. I highly recommend watching WWDC 2018: What’s New in User Notifications and see here.

Main changes are:

  • group notifications
  • provisional notifications
  • critical notifications
  • ability to interact with the notifications in the extensions

There are too many settings that need to be set right for it to work. I\'ll try to dissect them and make it easier to understand.

Overall, several things are important.

  • the overall difference between a silent and user notification
  • different types of user notifications
  • how a remote notification, i.e. the payload, is configured from your server
  • how to enable push notifications and remote notifications from background modes on your project
  • how to register your token for remote and silent notifications
  • how to request permission for user notifications
  • enabling \'background app refresh\' and \'notifications\' from the device
  • what is content-available
  • understanding that the iOS is upstream to your app when it comes to receiving a remote notification
  • what happens when the OS receives notifications when the app has been user-terminated
  • A note on reliability and APNs architecture

I highly recommend everyone to watch the first 7 minutes of: WWDC 2015: What\'s new in Notifications. From there, the presenter mentions that there are 2 major types of notifications:

Silent Notifications

They happen in the background, hence you never see any alert/badge/sound. Things get downloaded without you knowing about them.

iOS 11 bug

See here. iOS 11 initial releases were buggy for silent notifications. Make sure you have the latest version for your testing, otherwise it may not work


User Notifications

As the name says, it has something to do with the user. That is, the user will see an alert/badge or hear a sound. It has 2 types.

Local Notifications

A Local Notification can be triggered in 3 different ways:

  • UNLocationNotificationTrigger: You see an alert when you\'re close to a Walmart store.

  • UNTimeIntervalNotificationTrigger: e.g. You see an alert every 10 minutes.

  • UNCalendarNotificationTrigger like December 1st 1:00PM 2017.

Remote Notifications

They are similar to localNotifications but they are triggered from the server, e.g. a WhatsApp message that has a From field (Mom) and a body field (I love you!).

Some random notes:

To receive a silent or remote notification, you need to register for a token using:

application.registerForRemoteNotifications()