【发布时间】:2016-11-24 20:44:28
【问题描述】:
我正在尝试使用 https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/6.3/notifications/push-notifications-native-ios-applications/ 提供的示例代码和步骤通过 Worklight 在 iOS 设备上发送推送通知
当我在 iOS 7 设备上运行应用程序时,我得到一个设备令牌,因此当我点击订阅按钮时,我得到一个成功的响应。即使我们没有在 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 设备我得到了设备令牌和设备正在被订阅,但同样的事情不适用于 iOS 9 设备。
请帮我获取 iOS 9 设备的设备令牌。
【问题讨论】:
标签: ios apple-push-notifications worklight-server