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

Clash with expo-notifications (for local notifications) on iOS #1480

Closed
2 of 3 tasks
jacklj opened this issue Jan 24, 2023 · 9 comments
Closed
2 of 3 tasks

Clash with expo-notifications (for local notifications) on iOS #1480

jacklj opened this issue Jan 24, 2023 · 9 comments
Assignees

Comments

@jacklj
Copy link

jacklj commented Jan 24, 2023

What happened?

I've got react-native-onesignal installed on a bare React Native project, and I've since installed expo-notifications to fire local notifications. I get this warning on iOS startup (it comes from this code here:

EXNotificationCenterDelegate encountered already present delegate of UNUserNotificationCenter: <OSUNUserNotificationCenterDelegate: 0x600003c68460>. EXNotificationCenterDelegate will not overwrite the value not to break other features of your app. In return, expo-notifications may not work properly. To fix this problem either remove setting of the second delegate or set the delegate to an instance of EXNotificationCenterDelegate manually afterwards.

I believe this is because OneSignal already sets its own delegate.

The result is: local notifications get delivered, but the foregrounded app notification handler doesn’t fire (nor does expo-notifications’ one).

To fix, I've tried to follow the advice given by the expo-notifications warning - set the delegate to an instance of EXNotificationCenterDelegate manually afterwards.:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // ... 

  EXNotificationCenterDelegate *expoNotifDelegate = [[EXNotificationCenterDelegate alloc] init];
  [[UNUserNotificationCenter currentNotificationCenter] setDelegate:expoNotifDelegate];
  
  //...
}

This builds successfully but then local notifications don't work at all.

This should be compatible with OneSignal, see here #958 (comment):

OneSignal does swizzle the UNUserNotificationCenter so even if you have [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; in your code it shouldn't break OneSignal.

Any ideas how to make expo-notifications work with OneSignal on iOS (it works fine on Android)? Thanks

Steps to reproduce?

1. Install onesignal-react-native
2. Install expo-notifications
3. Schedule local notifications on iOS - the legacy onesignal native handler fires, neither JS handlers fire 
4. Try and set the delegate manually - it breaks local notifs completely

What did you expect to happen?

They should be compatible, as onesignal-react-native doesn’t implement local notifs, so we need to be able to use other libraries to implement them

React Native OneSignal SDK version

Release 4.5.0

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

EXNotificationCenterDelegate encountered already present delegate of UNUserNotificationCenter: <OSUNUserNotificationCenterDelegate: 0x600003c68460>. EXNotificationCenterDelegate will not overwrite the value not to break other features of your app. In return, expo-notifications may not work properly. To fix this problem either remove setting of the second delegate or set the delegate to an instance of EXNotificationCenterDelegate manually afterwards.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jacklj jacklj changed the title Clash with expo-notifications on iOS Clash with expo-notifications (for local notifications) on iOS Jan 24, 2023
@brismithers
Copy link
Contributor

brismithers commented Jan 27, 2023

Hi @jacklj thank you for reporting, we will look into this and let you know what we find. Can you show where you initialize the OneSignal SDK in relation to your didFinishLaunchingWithOptions code above?

@brismithers brismithers self-assigned this Jan 27, 2023
@brismithers
Copy link
Contributor

@jacklj I did a quick edit to my initial message and not sure you saw it. Can you show where you initialize the OneSignal SDK in relation to your didFinishLaunchingWithOptions code above? Thanks!

@jacklj
Copy link
Author

jacklj commented Jan 30, 2023

Thanks @brismithers, didn't see the update.

We followed the docs here https://documentation.onesignal.com/docs/react-native-sdk-setup - there is no OneSignal setup code in AppDelegate, just the OneSignalNotificationServiceExtension and then the initialization code in Javascript (in App.js).

@brismithers
Copy link
Contributor

@jacklj confirming that I am seeing the same thing, working through why/what needs to change

@brismithers
Copy link
Contributor

Hey @jacklj I don't have a good update, just letting you know I continue to try to figure this out. For context, I'm having trouble getting expo-notifications without onesignal-react-native to deliver a local notification while the app is in the foreground (local notifications while in background are delivered successfully). I think I'm running up against this issue.

I will mention one thing. In your original report you indicated the OneSignal notification received handler does not receive control when a local notification is received. I can say this is expected behavior. The OneSignal notification received handler will only get control for notifications sent by OneSignal.

So you must rely on expo's notification received handler for local notifications. And this is where I am currently stuck :).

Will keep at it!

@radoam1
Copy link

radoam1 commented Sep 22, 2023

I have similar problem when I have a both installed a listeners form expo-notifications don't work, any progres on this issue ?

@Klyado
Copy link

Klyado commented Oct 11, 2023

Hi there,

I've got the exact same issue. Any news about this @brismithers ?

@neilljordan
Copy link

Same here. Any suggestions?

@jennantilla
Copy link
Contributor

Hello there! Apologies that this issue has gone stale. Can anyone still experiencing this on the latest sdk release please open a new issue with updated reproduction steps? We will be happy to assist.

Thanks!

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

No branches or pull requests

6 participants