Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why registering for push notifications every time a user launch an app?

In the Apple documentation you can find the following sentence :

An application should register every time it launches and give its provider the current token. It calls registerForRemoteNotificationTypes: to kick off the registration process.

So when I implemented the push notification in my app I had to register the device, and I did what they said in that documentation: registering every time a user launch my app. The token that I receive from the APNS is always the same for a given user.

My question is: why do I need to register everytime if the APNS gives me always the same token?

I read somewhere than a token can change if a user swipe his iPhone or the app. Is it the only case?

Thank you !

like image 639
MartinMoizard Avatar asked Nov 07 '10 10:11

MartinMoizard


People also ask

Why are push notifications important for apps?

A major benefit of push notifications is that they provide a direct engagement channel that increases retention. To receive push notifications from your app, a user must either have your app downloaded or have already visited your website and opted-in to receive notifications.

Does an app need to be open for push notifications?

Push notifications are small, pop-up messages sent to a user's device by a mobile app that appear even when the app isn't open. These notifications are designed to grab attention and can convey reminders, updates, promotions, and more. Push notifications can consist of a title, a message, an image, and a URL.

Why are push notifications push notifications?

What are push notifications? # Push messages enable you to bring information to the attention of your users even when they're not using your website. They're called push messages because you can "push" information to your users even when they're not active.

What is Apple push notification used for?

Apple Push Notification service (APNs) is a cloud service that allows approved third-party apps installed on Apple devices to send push notifications from a remote server to users over a secure connection. For example, a newstand app might use APNs to send a text alert to an iPhone user about a breaking news story.


1 Answers

The token that I receive from the APNS is always the same for a given user.

Except it isn't, basically because there's nothing you can hang onto as being "a user" in the iPhone setup. The device token is always the same for each app for each device. So different apps on the same device get different tokens. The same app on two different devices gets two different tokens.

The crucial thing to note, and this is mentioned in the APNS guide, is that a user may back up their apps, settings, everything. Then they can drop their phone down the toilet. When they get their replacement phone, they can take their backup and restore it onto their new phone. Bingo - same app, same user, different device, and different token.

As far as your app is concerned, nothing has changed since the last time it ran - it doesn't know that it's actually running on a different device now. The only way it knows is because it asks for the 'current' device token, and hey presto it's a different token to last time.

You can choose to cache the token and check it against the token you just received (e.g. save it in your NSUserDefaults) - that way you don't have to communicate it back to the server unless it has changed since the last run, but you absolutely do have to check, otherwise your users will come complaining that they don't get push notifications any more since they replaced their phone.

like image 170
MrCranky Avatar answered Oct 09 '22 17:10

MrCranky