苹果推送通知注册和设备令牌接收的澄清?

5

我正在开发一款带有苹果推送通知集成的iPhone应用程序,对此我有一些疑问。

  1. 如果用户在APNS注册提醒中点击“不允许”按钮,我们的代码仍然会从APNS接收到设备令牌吗?

  2. 我已经测试过,当用户关闭iPhone通知时,应用程序仍然可以从APNS接收到设备令牌。这是正确的吗?

请问有人能够澄清这些疑问吗?

2个回答

9
  1. In my understanding on APNS, it doesn't depend on the user's action (as you mentioned that if when the user clicks on "Don't Allow" button) for your iOS to receive the Device Token.

    If you included in your app:

    - (void)application:didRegisterForRemoteNotificationsWithDeviceToken        
    

    This means that your iOS-based app is sending a request for Push Notification registration. In return, Apple sends the Device Token to the iOS; then the iOS sends the token to the app and then the app sends it to their service provider.

    Note that when the user is asked "Don't Allow" doesn't mean that you're not going to receive the device token. "Don't Allow" refers to the action to be taken to any notification received by the app that is intended for the user. Say, location. This is a whole different thing. This means that the user doesn't allow the app to use his/her location.

  2. Yes. it still receives the Device Token as what I have discussed in my answer to your question in #1. This is only a setting for your app, which means that you won't be receiving any visible notification (badge, message or a sound) whenever there are updates about any information in relevance to your application. It's like setting your Facebook account to only receive notifications when your friends sends you a private message. Other than that, you won't be notified at all.

    The process of enabling APNS is:

    1. Request for certificate Authority
    2. Create app id
    3. Configuring AppId for Push Notifications
    4. Create provisioning profile
    5. Provisioning a device
    6. Enabling the profile in Xcode
    7. Creating push notification provider.

如果想更好地了解APNS,请查看这个链接


感谢您的回答。从您的回答中我理解到,如果用户取消了苹果推送通知请求,我们的应用程序会自动从APNS接收设备令牌。我是不是对的?无论是允许还是不允许,应用都会从APNS接收设备令牌。请告诉我这是否正确?谢谢。 - Gopinath
非常感谢您的快速回答和帮助。但是,用户不会收到来自APNS的任何通知,对吗?我们如何找出用户取消了苹果推送通知服务?提前致谢。 - Gopinath
Kimpoy是正确的。我创建了一个带有推送通知的示例应用程序。当我的应用程序第一次启动时,我点击了“不允许”,但仍然调用了didRegisterForRemoteNotificationsWithDeviceToken,我得到了设备令牌。之后,我杀死了应用程序并重新启动,仍然获得了设备令牌。因此,根据示例应用程序,即使用户选择了“不允许”,我们仍将获得设备令牌。正如Kimpoy所提到的,“不允许”是指针对用户的任何通知接收到的操作。感谢Kimpoy的解释。 - iOSAppDev
@Kimpoy,你有没有尝试检查一下?我已经检查过了。对我来说是错误的。当用户点击“不允许”时,用户将无法获取设备令牌,并且didRegisterForRemoteNotificationsWithDeviceToken不会被调用。 - darshan
@Kimpoy 如果用户在IOS 8上选择“不允许”,我是否能获取设备令牌? - Radix
显示剩余3条评论

5

我已经测试过Xcode 6.1和iOS8.1.2。目前只有两种情况下会生成设备令牌:

  1. 使用苹果默认的“允许”选项
  2. 在“设置”-“通知”-“应用程序”-“允许通知(开启)”之后,手动更改

如果第一次拒绝苹果的同意,将不会生成设备令牌,直到在设置页面中手动更改该值。


1
在第二种情况下,我们如何获取令牌? - Bang Dao

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接