ios - 在 App-Code 中注册 Apple Push Notification

标签 ios cocoa-touch apple-push-notifications devicetoken

我写了一个 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/

相关文章:

iphone - 收到的远程通知没有出现在通知中心,但出现了应用程序图标上的角标(Badge)编号

ios - 在其中添加新组件时,Scrollview 不会调整大小

ios - 如何从数组中删除包含字典的数组对象

ios - 在两个 UIViewController 堆栈之间转换

objective-c - NSRegularExpression 字符串由

ios - 从 App Store 下载的应用程序有 BadDeviceToken,从源代码构建没有

ios - 当我改变它的大小时,我如何计算重绘 UIButton 的时间?

objective-c - 添加额外的 UIImage 到 TTPhotoViewController

ios - 有什么办法可以知道我按过哪个按钮吗?

swift - UIImage 的 UNNotificationAttachment 超出内存