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

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

问题描述

在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.

所以当我在我的app中实现推送通知时,我必须注册设备,我按照他们在文档中所说的做了:每次用户启动我的应用程序时注册。
我从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.

除了它不是' t,基本上是因为在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指南中提到的是,用户可以备份他们的应用程序,设置,一切。然后他们可以把手机放下马桶。当他们获得更换手机时,他们可以将备份恢复到新手机上。宾果游戏 - 相同的应用,相同的用户,不同的设备,和不同的令牌

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天全站免登陆