我写了一个 iPad 应用程序,它通过 apns 接收远程推送通知。 该应用程序审查通知并正确处理它们。
在 AppDelegate.mi 中调用:
registerForRemoteNotificationTypes:
我还有:
application: didRegisterForRemoteNotificationsWithDeviceToken:
设置和所有工作就像一个魅力。
在委托(delegate)中,我构建了一个指向服务器上注册脚本的 url。 Delegate 被调用,这导致调用 url 在我的服务器应用程序中注册设备等以发送推送通知。
但是!如果用户是第一次启动应用程序,那么到目前为止他还没有设置凭据。该应用程序注册接收远程通知,但我没有“ key ”告诉我哪个用户属于我服务器上的哪个设备。
我考虑过稍后调用注册 URL(在 App 中设置凭据之后),但是我需要可用的 DeviceToken,我在委托(delegate)之外没有它
didRegisterForRemoteNotificationsWithDeviceToken:
我该如何解决这个问题?我必须将 deviceToken 和用户名发送到我的服务器,以便稍后能够将通知发送给用户......
希望这个破坏描述是可以理解的:)
感谢任何帮助...
最佳答案
您希望您的 DeviceToken 可以在您的应用委托(delegate)之外访问,这听起来像是。这应该有助于解决您的问题:How to use the device token in method other than didRegisterForRemoteNotificationsWithDeviceToken?
关于ios - 在 App-Code 中注册 Apple Push Notification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8656740/