3

I want to send silent notifications to my tvOS application. Does this require asking the user for notification permissions? Or is it enough to just register for remote notifications and enable the matching app capabilities in Info.plist?

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted: Bool, error: Error?) in
    if error != nil {
        print(error?.localizedDescription ?? "error requesting notification authorization")
    }
}
UIApplication.shared.registerForRemoteNotifications()
juanjo
  • 3,737
  • 3
  • 39
  • 44
funkenstrahlen
  • 3,032
  • 2
  • 28
  • 40
  • Possible duplicate of [Is Silent Remote Notifications possible if user has disabled push for the app?](https://stackoverflow.com/questions/30644343/is-silent-remote-notifications-possible-if-user-has-disabled-push-for-the-app) – Glenn Posadas Oct 13 '17 at 10:36
  • I saw the other thread but it is not quite the same. Do I need to register for remote notifications even when asking the user is not required? – funkenstrahlen Oct 13 '17 at 10:41

5 Answers5

4

From Apple Docs

If your app's local or remote notifications involve user interactions, you must request authorization for the system to perfom those interactions on your app's behalf. Interactions include displaying an alert, playing a sound, or badging the app's icon.

In iOS, the fact of showing a notification and allow sending push content from the cloud to the app are two separate things. In your case the "silent notification" does not involve any interaction with the user, thus, you do not need to request this permission. But this does not prevent you from receiving the push token in order to push content to the app from the cloud. (you will receive a push token no matter what the user answer is).

I've never done this in tvOS, however as per the documentation it should be the same.

tomacco
  • 710
  • 4
  • 26
  • 1
    However, you still need to call : UIApplication.shared.registerForRemoteNotifications(); to register with APNS and receive a device token. – paiego Apr 09 '20 at 18:26
0

Do I need to register for remote notifications even when asking the user is not required?

In the Apple's Local and Remote Push Notification Documentation, specifically in its Configuring a Silent Notification section, you would see that you will be needing to setup your project's capabilities, and specifically checking the Remote Notifications capability, like so:

enter image description here

Therefore you will need to setup the certificates and other necessary stuff in Apple's Developer Website. Hope it helps!

Glenn Posadas
  • 12,555
  • 6
  • 54
  • 95
-2

This is the same step required for silent and push notifications.

-3

In iOS, tvOS, and watchOS, apps must have authorization to display alerts, play sounds, or badge the app’s icon in response to incoming notifications. Requesting authorization puts control of those interactions in the hands of the user, who can grant or deny your request. The user can also change the authorization settings for your app later in the system settings.

Source: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SupportingNotificationsinYourApp.html#//apple_ref/doc/uid/TP40008194-CH4-SW1

-3
{
  "aps" : 
    {
     "alert" : 
      {
          "loc-key" : "GAME_PLAY_REQUEST_FORMAT",
          "loc-args" : [ "Jenna", "Frank"]},
          "sound" : "chime.aiff"
      },
     "acme" : "foo"
     }

Remove "sound":"chime.aiff"
Sangram Shivankar
  • 3,535
  • 3
  • 26
  • 38