React-native-onesignal: didReceiveRemoteNotification not working in AppDelegate.m

Created on 30 Oct 2018  ·  4Comments  ·  Source: OneSignal/react-native-onesignal

Description:

I'm trying to use Freschat SDK to handle theri push notifications inside AppDelegate.m but it doesn't seem to work with onesignal service extension.

Environment

  1. What version of the OneSignal React-Native SDK are you using? 3.2.7
  2. How did you add the SDK to your project (eg. npm) npm

Steps to Reproduce Issue:

  • Install the OneSignal SDK using npm into your project

  • Initialize the SDK in the iOS AppDelegate
  • Attempt to receive a push notification
  • Anything else:

    (crash stacktraces, as well as any other information here)

    Most helpful comment

    Sorry for the (very) delayed response here, but there are a few things.

    First of all, application:didReceiveRemoteNotification: is deprecated. You will want to use application:didReceiveRemoteNotification:fetchCompletionHandler: instead. But I would recommend against using this as well, you should definitely be using the UNUserNotificationCenterDelegate methods if you want to execute native code when a notification is received.

    The Notification Service Extension doesn't override this method.

    To use the UNUserNotificationCenterDelegate, edit AppDelegate.h and add:

    #import <UserNotifications/UserNotifications.h>
    

    Then change the AppDelegate interface to implement the UNUserNotificationCenterDelegate protocol:

    @interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
    

    In AppDelegate.m inside of the didFinishLaunchingWithOptions: method, you should add the following line:

    UNUserNotificationCenter.currentNotificationCenter.delegate = self;
    

    Finally, you can add the following method which will now be called whenever a notification is received:

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

    Closing since this isn't an issue with our SDK

    All 4 comments

    @nitish1099 What do you mean when you say "it doesn't seem to work with OneSignal service extension"...?

    Also, Freschat's SDK is closed source so unfortunately there's not much we can do in terms of debugging the incompatibility. When you remove their SDK from your project, does the AppDelegate method get called?

    You may need to use the UNUserNotificationCenterDelegate methods instead to receive notification event method calls

    @Nightsd01 Not being a native developer, can you tell me if the notification service extension overrides the didReceiveRemoteNotification? Also could you tell me how to use UNUserNotificationCenterDelegate or if you can share a guide I can refer to.

    @Nightsd01 Any updates?

    Sorry for the (very) delayed response here, but there are a few things.

    First of all, application:didReceiveRemoteNotification: is deprecated. You will want to use application:didReceiveRemoteNotification:fetchCompletionHandler: instead. But I would recommend against using this as well, you should definitely be using the UNUserNotificationCenterDelegate methods if you want to execute native code when a notification is received.

    The Notification Service Extension doesn't override this method.

    To use the UNUserNotificationCenterDelegate, edit AppDelegate.h and add:

    #import <UserNotifications/UserNotifications.h>
    

    Then change the AppDelegate interface to implement the UNUserNotificationCenterDelegate protocol:

    @interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
    

    In AppDelegate.m inside of the didFinishLaunchingWithOptions: method, you should add the following line:

    UNUserNotificationCenter.currentNotificationCenter.delegate = self;
    

    Finally, you can add the following method which will now be called whenever a notification is received:

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

    Closing since this isn't an issue with our SDK

    Was this page helpful?
    0 / 5 - 0 ratings