ios - 将 iOS 原生推送通知与 WorkLight 集成时,iOS 9 设备未提供设备 token

标签 ios apple-push-notifications worklight-server

我正在尝试使用 https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/6.3/notifications/push-notifications-native-ios-applications/ 提供的示例代码和步骤通过 Worklight 在 iOS 设备上发送推送通知

当我在 iOS 7 设备上运行应用程序时,我得到一个设备 token ,因此当我点击订阅按钮时,我得到一个成功的响应。即使我们没有在 didFinishLaunchingWithOptions 中为 registeringForRemoteNotifications 编写任何代码,这仍然有效。

但是当我在 iOS 8 和 iOS 9 设备上运行相同的代码时,我在控制台上收到以下消息:

iOSNativePush[1119:372642] registerForRemoteNotificationTypes: 在 iOS 8.0 及更高版本中不受支持。

为了让我的应用程序在 iOS>=8 设备上运行,我编写了以下代码:

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
 {
// Override point for customization after application launch.

if([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
   {
    [[UIApplication sharedApplication] registerUserNotificationSettings:  [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]];

    [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
else
   {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |    UIUserNotificationTypeSound)];
   }
return YES;
   }


- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
  [application registerForRemoteNotifications];
}

我仍然在控制台中收到“ iOSNativePush[1119:372642] registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later ”消息,但对于 iOS 8 设备 我正在获取设备 token 并且设备正在被订阅,但同样的事情不适用于 iOS 9 设备。

我也引用了以下链接,但没有运气
https://www.ibm.com/developerworks/community/blogs/worklight/entry/understanding-and-setting-up-push-notifications-in-development-evnironment?lang=en

请帮我获取 iOS 9 设备的设备 token 。

最佳答案

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}

Use above code

关于ios - 将 iOS 原生推送通知与 WorkLight 集成时,iOS 9 设备未提供设备 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38501149/

相关文章:

ibm-mobilefirst - IBM Worklight - 从适配器加载属性文件

ibm-mobilefirst - 如何修复为 Wo​​rklight 项目找不到 MBean?

ios:Libity 服务器上的 worklight apns 证书位置

javascript - 如何使本地 APNS 推送通知静音?

ios - WhatsApp 如何在 iOS 上加密推送通知?

ios - Device Farm 在 iOS 上将 "extra data"的 zip 存档的内容放在哪里?

iOS获取UTC时间戳

ios - 访问推送通知列表

ios - 如何在移动到屏幕背景或杀死 App 时显示 UIAlertView?

ios - 如何在其他开发人员设备上安装我的 xcode 项目进行测试