2

Reading from WWDC 2015 Session 720 it says:

Silent notifications are enabled by default. The user does not need to give permission to your app to use them. You can start using them without asking the user for permission

My question is:

  1. How do you get the push token to use without registering for remotes?
  2. If I still have to register, then what does "default" mean here?

Does it mean that you don't have to prompt to register, but still you have to register under the hood upon app launch? Which likely means default was a very bad word to choose?

I read this question but it doesn't answer this.

mfaani
  • 33,269
  • 19
  • 164
  • 293
  • [Here](http://www.g8production.com/post/72656082173/ios7-multitasking-silent-notifications) is your answer. – iphonic Feb 16 '17 at 18:50
  • @iphonic The link doesn't provide an answer. Doesn't explain what default means. I made an edit to emphasize on that. – mfaani Feb 16 '17 at 18:55

3 Answers3

3

You still have to register for push notifications. Just don't register the UIUserNotificationTypeAlert or UIUserNotificationTypeBadge or UIUserNotificationTypeSound type to make it silent and so that the user doesn't get prompted to enable push notifications

mfaani
  • 33,269
  • 19
  • 164
  • 293
Lefteris
  • 14,550
  • 2
  • 56
  • 95
1

The user doesn't need to give permission to your app so you can use them, but you still need the app to register for notifications in order to get a device token. Without registering there's no way you can get a device token, and without a device token there's no way you can send a notification to a device.

pera
  • 155
  • 4
  • so the term default is very bad word to be used. rather it means you don't have to prompt the user, you can just register under the hood? – mfaani Feb 16 '17 at 18:59
0

Not. You still need to register for remote notifications. Although they're silent does not mean there not remote, right?

You register for remote notifications, obtain the token, send it to the server and then send a notification without sound to that token.

EDIT

To respond to your edit: YES, the term default might be misleading or read in a wrong ways.

Silent notifications may be enabled, but you don't have a way to send them to the device. I think they wrote in the the docs so you don't go to the Preferences app and search for the "Silent Notifications" toggle. Sounds more like a end-user explanation.

So they are enabled, but you need the user-prompt (say: "register for notifications") to obtain the token.

EDIT II

Apple could have left out this paragraph entirely.

Julian F. Weinert
  • 7,474
  • 7
  • 59
  • 107
  • Does the term "default" mean the registration can happen without a prompt as in the initial launch we can get a token for silent notifications without user permission? Basically we don't need to do anything like [here](https://i.stack.imgur.com/BzAd5l.png). We only need such a prompt, if we are showing (badge, banner, sound). Basically Pera's answer? – mfaani Feb 16 '17 at 18:57
  • Yep – We answered all at the same time – correctly. Then you edited your question and unfortunately changed it's scope, yo our answers aren't correct anymore. – Julian F. Weinert Feb 16 '17 at 19:17
  • do you have an answer for what does default mean? It's implied in my question and I just edited since no one addressed it properly – mfaani Feb 16 '17 at 19:21
  • Check out my own edit – I hope it's answer enough ;) – Julian F. Weinert Feb 16 '17 at 19:22
  • Are you sure that you need to prompt the user? The other 2 answers say you don't. You only need it if you wanna prompt something UI like a badge, alert, sound... – mfaani Feb 16 '17 at 19:24
  • Where do you get the token from? – Julian F. Weinert Feb 16 '17 at 19:25
  • From a process the displays the prompt. And you can't send remote notifications without this token. – Julian F. Weinert Feb 16 '17 at 19:25
  • @you get it without prompting. just by calling `registerForRemoteNotifications()` you only get a prompt if you do : `application.registerUserNotificationSettings(notificationSettings)` Where your notifications are `let notificationTypes: UIUserNotificationType = [.Alert, .Badge, .Sound]` ie you wanna disrupt the user – mfaani Feb 16 '17 at 19:33
  • Did you test this on a real device? I'm presented with the prompt after calling `[UIApplication registerUserNotificationSettings:]` – Julian F. Weinert Feb 16 '17 at 19:40
  • You seem to be using Swift. It's incomplete and this looks like it's insecure too (???). Could you check if it's a bug in the Swift implementation? – Julian F. Weinert Feb 16 '17 at 19:41
  • Did you confirm the prompt already during development? You'll get this prompt only once the application was removed for 24h (Apple changed something about it, go check it). Once confirmed, you'll get the token without prompt unless you reinstall the app. – Julian F. Weinert Feb 16 '17 at 19:44
  • you got prompted without having any `application. registerUserNotificationSettings(YourSettings)`??? I'll have to test, but don't have device now. Will do later and post result – mfaani Feb 16 '17 at 19:44
  • Yes. This would be the correct ways to do it. Unless, if I'm using the old, deprecated version without settings, I'm not getting a token from the system – Julian F. Weinert Feb 16 '17 at 19:45
  • So I just tested. when I only included: `registerForRemoteNotifications()` I **wasn't** prompted to anything. Only when I used `application.registerUserNotificationSettings(settings)` I got prompted. – mfaani Feb 16 '17 at 20:06
  • Now the last question is _why_ you get the token when calling the "wrong" function (extra attention to the double quotes, as I don't have a clue on Swift). Did you read my comment with the 24h / reinstallation-thing? Could still that one? – Julian F. Weinert Feb 16 '17 at 20:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/135889/discussion-between-honey-and-julian-f-weinert). – mfaani Feb 16 '17 at 20:11