如何在 APNS 中发送设备令牌

发布于 2024-08-03 20:05:45 字数 213 浏览 5 评论 0原文

我已经实现了以下代码但没有获得设备令牌?

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"deviceToken: %@", deviceToken);
}

I Have implemented following code but not getting the Device Token?

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"deviceToken: %@", deviceToken);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九歌凝 2024-08-10 20:05:45

如果您还没有这样做,您应该在 didFinishLaunchingWithOptions 中调用 registerForRemoteNotificationTypes。大致如下:

[[UIApplication sharedApplication]
     registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                         UIRemoteNotificationTypeSound |
                                         UIRemoteNotificationTypeAlert)];

您还应该有一个在注册失败时调用的 didFailToRegisterForRemoteNotificationsWithError 方法。它得到的 NSerror 应该告诉你更多关于它可能失败的原因。

If you don't already, you should have a call to registerForRemoteNotificationTypes in your didFinishLaunchingWithOptions. Something along the lines of:

[[UIApplication sharedApplication]
     registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                         UIRemoteNotificationTypeSound |
                                         UIRemoteNotificationTypeAlert)];

You should also have a didFailToRegisterForRemoteNotificationsWithError method that gets called if registration fails. The NSerror it gets should tell you more about why it might be failing.

牵你手 2024-08-10 20:05:45

您正在模拟器内部尝试吗?
推送通知和相关的 appdelagate 事件在模拟器上不起作用。

如果您正在使用该设备,
确保您的应用程序的捆绑包标识符必须与您在 iphone 预配置原型上创建 AppID 期间定义的推送 ssl 捆绑包标识符相同。

Are you trying inside of the simulator ?
Push notification and related appdelagate events doesn't work on simulator.

If you are using the device,
Make sure that bundle identifier of your application must be same with your push ssl bundle identitifier which you defined during creating AppID on iphone privisioning protal.

感性 2024-08-10 20:05:45

为了向 APN 注册您的设备,您首先必须调用

    [[UIApplication sharedApplication]
 registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

这通常是在您的 AppDelegate 中编写的(在 didFinishLaunching 中)。
然后确保您已经实现了它,

didRegisterForRemoteNotificationsWithDeviceToken 

它为您提供了设备令牌,并

didFailToRegisterForRemoteNotificationsWithError

为您提供了代码可能遇到的错误。

For registering your device with APNs, you will first have to call

    [[UIApplication sharedApplication]
 registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

this is usually written in your AppDelegate (in didFinishLaunching ).
Then make sure you have implemented the

didRegisterForRemoteNotificationsWithDeviceToken 

which provides you with the device token and

didFailToRegisterForRemoteNotificationsWithError

which gives you the error your code might have encountered.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文