远程通知令牌处理
我正在注册我的 iPhone 应用程序以进行远程通知。
这是我的场景:
- 用户打开我的应用程序并注册远程通知
- 用户关闭我的应用程序的通知
- 用户打开我的应用程序
- 用户打开我的应用程序的通知
我的问题是:
- 是否可以检查用户是否已禁用我的应用程序的远程通知在我的应用程序代码中?
- 如果我在没有用户关闭应用程序通知的情况下请求新令牌,则检索到的令牌会不同还是始终相同?
- 我应该在每次启动应用程序时请求新的令牌吗?
I'm registering my iPhone application for Remote Notification.
Here my scenario:
- User opens my app and register for remote notification
- User turns notification off for my app
- User open my app
- User turns notification on for my app
My questions are:
- Is it possible to check if the user has disabled remote notification for my app inside my app's code?
- If I request a new token without user turn off notification for my app, the retrieved token is different or is always the same?
- Should I request a new token every time I start my app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么您想了解 UIRemoteNotifications 吗? :) 很酷,因为它们并不像人们经常想象的那么复杂。不过,我将以相反的顺序回答你的问题。它比方式更流畅。
您的问题:
有点像。使用 UIRemoteNotifications,您永远不会真正请求令牌,而是请求权限并接收令牌。您应该做的是在应用程序委托中实现
application:didRegisterForRemoteNotificationsWithDeviceToken:
。此方法(及其错误捕获同级application:didFailToRegisterForRemoteNotificationsWithError:
)是registerForRemoteNotificationTypes:
的回调。最佳做法是在application:didFinishLaunchingWithOptions:
期间调用registerForRemoteNotificationTypes:
。 (不用担心所有方法名称到处乱飞。我很快就会按代码解释)。或许。出于安全原因,设备令牌可能会发生变化,但一般来说,您不需要太担心它的变化。
为什么,是的。
UIApplicationDelegate
有一个名为enabledRemoteNotificationTypes
的方法,它获取您请求并由您的用户启用的所有远程通知类型。稍后会详细介绍。总而言之:
最终,您应该得到如下结果:
So you want to know about UIRemoteNotifications? :) Cool, because they're not really as complex as people often make them out to be. Though, I am going to address your questions in reverse order. It flows better than way.
Your questions:
Sort of. With UIRemoteNotifications, you never really request a token, so much as request permission and receive a token. What you should do is implement
application:didRegisterForRemoteNotificationsWithDeviceToken:
in your app delegate. This method (along with its error-catching siblingapplication:didFailToRegisterForRemoteNotificationsWithError:
) is the callback forregisterForRemoteNotificationTypes:
. It's best practice to callregisterForRemoteNotificationTypes:
duringapplication:didFinishLaunchingWithOptions:
. (Don't worry about all of the method names flying around. I'll explain codewise shortly).Maybe. The device token is subject to change for security reasons, but in general you shouldn't need to be too concerned with it changing.
Why, yes it is.
UIApplicationDelegate
has a method calledenabledRemoteNotificationTypes
, which gets all of the remote notification types requested by you and enabled by your user. More on that shortly.Putting it all together:
At the end of the day, you should end up with something like this:
2.
可以根据此 SO 更改检索到的令牌。
3.
是的,以防令牌发生变化。
2.
The retrieved token can be changed according to this SO.
3.
Yes, in case the token changes.