【问题标题】:Device token not coming for iOS 9 device while integrating iOS native push notification with WorkLight将 iOS 原生推送通知与 WorkLight 集成时,iOS 9 设备未提供设备令牌
【发布时间】: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 设备。

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

请帮我获取 iOS 9 设备的设备令牌。

【问题讨论】:

    标签: ios apple-push-notifications worklight-server


    【解决方案1】:

    此问题已在 MobileFirst 6.3 及更高版本的后续 iFix 中得到修复。

    解决:

    1) 将您的 MobileFirst 工作室更新到最新的 iFix。

    2) 添加新的 iOS 原生环境。

    3) 用新生成的 (with iFix) 替换示例的本机文件夹

    4) 清理、构建和部署。

    【讨论】:

    • 谢谢,我试试这个。
    【解决方案2】:
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    

    使用上面的代码

    【讨论】:

    • 感谢您的回复,我不知道如何,但我的旧代码今天可以使用,我获得了 iOS 9 的设备令牌 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2015-08-29
    • 2018-08-07
    相关资源
    最近更新 更多