What is difference between remote notification and silent notification in iOS?

后端 未结 3 770
攒了一身酷
攒了一身酷 2020-11-22 15:26

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 loc

相关标签:
3条回答
  • 2020-11-22 15:34

    Silent push notification reaches device, user does not know anything about the notification but his app gets the notification and app will be given some time to download new content and present it to the user, regardless to the state of the app (i.e. running or not running)

    Remote push notification method is called only when your app is running. If app is suspended or not running, then the system wakes up or launches your app and puts it into the background running state before calling the method. This method is intended for showing the updated content to the user.When this method is called, your app has up to 30 seconds of wall-clock time to perform the download operation and call the specified completion handler block. If the handler is not called in time, your app will be suspended.

    For more technical details, you can go through this links:

    Apple Notifications

    Silent Notifications

    0 讨论(0)
  • 2020-11-22 15:37

    The push notification will let the user know that they receive a notification (Showing the notification popup for example). The silent notification will update, but the user won't get notified about it. In any case, you can perform actions when notified with silent, just as if it was a push notification. The only difference is the user will not get notify with the popup notification.

    With push notification:

    With silent notification:

    The difference is in the payload:

    Push notification:

         aps {
           content-available: 1
           alert: {...}
         }
    

    Silent notification:

        aps {
          content-available: 0
          alert: {...}
        }
    

    And you have to set in Capabilities the background mode you choose.

    0 讨论(0)
  • 2020-11-22 15:54

    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 read this amazing and must read article.

    Main changes are:

    • grouped notifications along with summary format
    • provisional notifications ie show notifications directly in notification center without user permission
    • critical notifications which ignores 'do not disturb' or 'mute'
    • ability to interact with the notifications in the extensions
    • ability to completely reset or update actions
    • ability to deeplink into app's notification Settings from phone's Notification Center

    IMPORTANT NOTE: Not sure since when but from the Apple docs, the 'silent notification' has been renamed to 'background notification'

    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 with APNs for remote and silent notifications and APNs architecture
    • 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!).

    Token registration and APNs architecture:

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

    application.registerForRemoteNotifications() 
    

    0 讨论(0)
提交回复
热议问题