为什么每次用户启动应用程序时都要注册推送通知? [英] Why registering for push notifications every time a user launch an app?

查看:30
本文介绍了为什么每次用户启动应用程序时都要注册推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Apple 文档中,您可以找到以下句子:

In the Apple documentation you can find the following sentence :

应用程序应在每次启动时进行注册,并为其提供者提供当前令牌.它调用 registerForRemoteNotificationTypes: 来启动注册过程.

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

因此,当我在我的应用程序中实现推送通知时,我必须注册设备,并且我按照他们在该文档中所说的去做:每次用户启动我的应用程序时都进行注册.对于给定用户,我从 APNS 收到的令牌始终相同.

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.

我的问题是:如果 APNS 总是给我相同的令牌,为什么我每次都需要注册?

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

我在某个地方读到,如果用户滑动他的 iPhone 或应用程序,令牌可以改变.这是唯一的情况吗?

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

谢谢!

推荐答案

对于给定用户,我从 APNS 收到的令牌始终相同.

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

除非它不是,基本上是因为在 iPhone 设置中没有什么可以让您成为用户".每个设备的每个应用的设备令牌始终相同.因此,同一设备上的不同应用会获得不同的令牌.两个不同设备上的同一个应用会获得两个不同的令牌.

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.

需要注意的关键一点(APNS 指南中提到)是用户可以备份他们的应用程序、设置等所有内容.然后他们就可以把手机扔到马桶上了.当他们拿到替换手机时,他们可以进行备份并将其恢复到新手机上.Bingo - 相同的应用、相同的用户、不同的设备、和不同的令牌.

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.

您可以选择缓存令牌并根据您刚刚收到的令牌进行检查(例如将其保存在您的 NSUserDefaults 中)——这样您就不必将其传回服务器,除非自上次运行以来它已更改,但您绝对必须检查,否则您的用户会抱怨自从他们更换手机后就再也没有收到推送通知.

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.

这篇关于为什么每次用户启动应用程序时都要注册推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆