关于 didRegisterForRemoteNotificationsWithDeviceToken 的任何通知?

psh*_*hah 5 nsnotifications nsnotificationcenter ios

当 didRegisterForRemoteNotificationsWithDeviceToken 被调用时,iOS 是否触发 NSNotification(包含 deviceToken)?

我知道我总是可以从 AppDelegate 中将令牌保存在 NSUserDefaults 中并在任何地方访问它,但我想知道是否有更好的方法。我在想一些类似 UIApplicationDidEnterBackgroundNotification 的东西。

更新:如果我想获取设备令牌而不在 AppDelegate 中实现该委托方法的用例。

Pet*_*ski 3

不需要。您需要实现 didRegisterForRemoteNotificationsWithDeviceToken 。我想在这种情况下反对 NSNotification 的一个论点是,您需要使用 didFailToRegisterForRemoteNotificationsWithError 智能地处理失败场景。