React-native-onesignal: One signal conflict with react-native-push-notification

Created on 16 Aug 2018  路  13Comments  路  Source: OneSignal/react-native-onesignal

Description:

Hi, I am trying to have local and remote notification for my apps. I am using react-native-push-notification for local notification and react-native-ios-notification-actions for action buttons (because OneSignal P2P notification doesn't provide action button). The local notification with action buttons work fine but after OneSignal.init() the notification actions button won't respond but only showing with the local notification.I tried to remove One signal SDK by rm-rf node_modules/react-native-onesignal, and the action buttons work fine without the One signal SDK. I am wondering is there a way that both libraries can work together without conflict?

Environment
3.2.6
npm install --save react-native-onesignal
react-native link react-native-onesignal

Steps to Reproduce Issue:

  1. Install the react-native-push-notification & react-native-ios-notification-actions using npm into your project
  2. Receive a local notification with working action buttons
  3. Install the OneSignal SDK using npm into your project
  4. Initialize the SDK in the iOS AppDelegate & componentDidMount()
  5. Receive a local notification from react-native-push-notification & react-native-ios-notification-actions libraries, but the action buttons won't respond.
  6. Remove the One Signal SDK using rm-rf node_modules/react-native-onesignal and unlink it.
  7. Receive a local notification with working action buttons.

Anything else:

I have been working on this issues for 2 days, and also looked into IOS native code to fix the issues but no luck. Thanks for advance for your help!

Compatibility Issue

Most helpful comment

Hello,

I have the same problem, if I use react-native-push-notification only, the didReceiveRemoteNotification function from the AppDelegate.m gets called (I've put a breakpoint inside the function for testing purpose) and everything works as expected.

Now, if I install OneSignal SDK and initialise it from the JS code, the didReceiveRemoteNotification function is not triggered anymore when I receive a regular notification.

This was working previously with the 3.0.x version of the SDK and the initialisation via the AppDelegate.m instead of the initialisation from the JS code.

More disturbing, if I install the SDK, setup the app extension but does not initialise the SDK at all, regular notifications are still not working and the didReceiveRemoteNotification is still not triggered.

I managed to receive the notifications back by implementing "UNUserNotificationCenter delegate " functions in the AppDelegate (which is not needed if OpenSignal SDK is not installed) but only when the app is in foreground...

Any idea where this might come from?

All 13 comments

@manxhong When you say the button does not respond, I am not sure what you mean? Can you send a screenshot perhaps?

@Nightsd01 when I click the notification action button (from react-native-ios-notification-actions library) to invoke a function, that function is not running.

@manxhong I notice you said you initialize the SDK in the AppDelegate _and_ in componentDidMount(). Please just initialize in componentDidMount(), there is no need to initialize in the app delegate or touch Objective-C at all.

That may not fix the issue but I'll be looking into it shortly.

@Nightsd01 sorry for the misleading, I didn't initialize oneSignal SDK in AppDelegate, I only added these line in AppDelegate for local notification.

```// Required to register for notifications

  • (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
    {
    [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
    }
    // Required for the register event.
  • (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
    [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
    }
    // Required for the notification event. You must call the completion handler after handling the remote notification.
  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
    {
    [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
    }
    // Required for the registrationError event.
  • (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    {
    [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
    }
    // Required for the localNotification event.
  • (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
    {
    [RCTPushNotificationManager didReceiveLocalNotification:notification];
    }

Hello,

I have the same problem, if I use react-native-push-notification only, the didReceiveRemoteNotification function from the AppDelegate.m gets called (I've put a breakpoint inside the function for testing purpose) and everything works as expected.

Now, if I install OneSignal SDK and initialise it from the JS code, the didReceiveRemoteNotification function is not triggered anymore when I receive a regular notification.

This was working previously with the 3.0.x version of the SDK and the initialisation via the AppDelegate.m instead of the initialisation from the JS code.

More disturbing, if I install the SDK, setup the app extension but does not initialise the SDK at all, regular notifications are still not working and the didReceiveRemoteNotification is still not triggered.

I managed to receive the notifications back by implementing "UNUserNotificationCenter delegate " functions in the AppDelegate (which is not needed if OpenSignal SDK is not installed) but only when the app is in foreground...

Any idea where this might come from?

I'm facing the same issue

This is a big problem, since OneSignal does not support local notifications.

Thanks for your patience everyone. @25matt12 , and Matthieu thanks for your workaround.

Just so people know, since iOS 10 the didReceiveRemoteNotification handler is deprecated and the new standard is to use the UNUserNotificationCenterDelegate

Folks really have three options here:

  1. Handle in the UNUserNotificationCenterDelegate (best bet)
  2. Use old app delegate set-up instructions where the app_id is configured in the AppDelegate and not JS
  3. Request the conflicting plugin's developer update to new UNUserNotificationCenterDelegate standard

Hello,

I have the same problem, didReceiveRemoteNotification function is not triggered when I receive a local notification.

I have done the following and now it works very well

/- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
}
/

-(void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler {

UILocalNotification *notification=[[UILocalNotification alloc] init];
notification.fireDate=response.notification.date;
notification.alertTitle=response.notification.request.content.title;
notification.alertBody=response.notification.request.content.body;
notification.soundName=@"default";
notification.userInfo=response.notification.request.content.userInfo;
notification.category=response.notification.request.content.categoryIdentifier;
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
completionHandler();
}

@AbdelrhmanFathy @25matt12 is still working for you? I can't for the life of me to make to work with the last version :(

@rgomezp Could you guys try to provide a working example. I am pinging everyone but I get no reply. I'm really considering switching from OneSignal (I'm a paying customer) because of this issue and lack of support :(

Hello all,
If you are seeing this issue, please head over to https://github.com/facebook/react-native/issues/26199 and try to prioritize that issue with React Native. Cheers!

@rborn Sorry but I'm not maintaining the project anymore however I can tell you that it was still working in November 2019.

@25matt12 I made it work in the end somehow, thanks

Was this page helpful?
0 / 5 - 0 ratings