React-native-onesignal: didReceiveRemoteNotification 在 AppDelegate.m 中不起作用

创建于 2018-10-30  ·  4评论  ·  资料来源: OneSignal/react-native-onesignal

描述:

我正在尝试使用 Freschat SDK 来处理 AppDelegate.m 中的推送通知,但它似乎不适用于 onesignal 服务扩展。

环境

  1. 您使用的是什么版本的 OneSignal React-Native SDK? 3.2.7
  2. 您是如何将 SDK 添加到您的项目中的(例如 npm) npm

重现问题的步骤:

  • 使用 npm 将 OneSignal SDK 安装到您的项目中

  • 在 iOS AppDelegate 中初始化 SDK
  • 尝试接收推送通知
  • 还要别的吗:

    (崩溃堆栈跟踪,以及此处的任何其他信息)

    最有用的评论

    很抱歉在这里(非常)延迟响应,但有一些事情。

    首先,不推荐使用application:didReceiveRemoteNotification: 。 您将要使用application:didReceiveRemoteNotification:fetchCompletionHandler:代替。 但是我也建议不要使用它,如果您想在收到通知时执行本机代码,则绝对应该使用UNUserNotificationCenterDelegate方法。

    通知服务扩展不会覆盖此方法。

    要使用UNUserNotificationCenterDelegate ,请编辑AppDelegate.h并添加:

    #import <UserNotifications/UserNotifications.h>
    

    然后改变AppDelegate接口来实现UNUserNotificationCenterDelegate协议:

    <strong i="18">@interface</strong> AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
    

    AppDelegate.m didFinishLaunchingWithOptions:方法内的

    UNUserNotificationCenter.currentNotificationCenter.delegate = self;
    

    最后,您可以添加以下方法,现在每当收到通知时都会调用该方法:

    -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
      //do stuff
    }
    

    关闭,因为这不是我们 SDK 的问题

    所有4条评论

    @nitish1099当您说“它似乎不适用于 OneSignal 服务扩展”时,您是什么意思...?

    此外,Freschat 的 SDK 是封闭源代码,因此不幸的是,我们在调试不兼容方面无能为力。 当您从项目中删除他们的 SDK 时,是否会调用 AppDelegate 方法?

    您可能需要使用UNUserNotificationCenterDelegate方法来接收通知事件方法调用

    @Nightsd01不是本地开发者,你能告诉我通知服务扩展是否覆盖了 didReceiveRemoteNotification 吗? 您还可以告诉我如何使用 UNUserNotificationCenterDelegate 或者您是否可以分享我可以参考的指南。

    @Nightsd01 有任何更新吗?

    很抱歉在这里(非常)延迟响应,但有一些事情。

    首先,不推荐使用application:didReceiveRemoteNotification: 。 您将要使用application:didReceiveRemoteNotification:fetchCompletionHandler:代替。 但是我也建议不要使用它,如果您想在收到通知时执行本机代码,则绝对应该使用UNUserNotificationCenterDelegate方法。

    通知服务扩展不会覆盖此方法。

    要使用UNUserNotificationCenterDelegate ,请编辑AppDelegate.h并添加:

    #import <UserNotifications/UserNotifications.h>
    

    然后改变AppDelegate接口来实现UNUserNotificationCenterDelegate协议:

    <strong i="18">@interface</strong> AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
    

    AppDelegate.m didFinishLaunchingWithOptions:方法内的

    UNUserNotificationCenter.currentNotificationCenter.delegate = self;
    

    最后,您可以添加以下方法,现在每当收到通知时都会调用该方法:

    -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
      //do stuff
    }
    

    关闭,因为这不是我们 SDK 的问题

    此页面是否有帮助?
    0 / 5 - 0 等级