Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One signal conflict with react-native-push-notification #605

Closed
manxhong opened this issue Aug 16, 2018 · 13 comments
Closed

One signal conflict with react-native-push-notification #605

manxhong opened this issue Aug 16, 2018 · 13 comments

Comments

@manxhong
Copy link

manxhong commented Aug 16, 2018

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!

@manxhong manxhong changed the title one signal conflict with react-native-push-notification One signal conflict with react-native-push-notification Aug 16, 2018
@Nightsd01
Copy link
Contributor

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

@manxhong
Copy link
Author

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

@Nightsd01
Copy link
Contributor

@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.

@manxhong
Copy link
Author

manxhong commented Aug 20, 2018

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

 - (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];
 }

@25matt12
Copy link

25matt12 commented Aug 24, 2018

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?

@nitish1099
Copy link

I'm facing the same issue

@rcidt
Copy link

rcidt commented Apr 4, 2019

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

@rgomezp
Copy link
Contributor

rgomezp commented May 28, 2019

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

@rgomezp rgomezp closed this as completed May 28, 2019
@AbdelrhmanFathy
Copy link

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();
}

@rborn
Copy link

rborn commented Mar 17, 2020

@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 :(

@rgomezp
Copy link
Contributor

rgomezp commented Apr 7, 2020

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

@25matt12
Copy link

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

@rborn
Copy link

rborn commented May 22, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants