0

I have already implemented PushnotificationIos , an api provided by react-native working fine.

Lately I have to implement pushnotification for android and I am trying to use react-native-firebase@4.x.x . I have platform specific handler but Works fine for android , but for IOS the app crashes while builing with the following error

VERSIONS DETAILS: react-native : 0.55 react-native-firebase:4.0.0

I tried to do dynamic import to get rid of react-native-firebase for ios but I am not convinced with the idea as its kind of hack , gives parser error. Dynamic import feature itself is not a stable one.

.enter image description here

santosh
  • 140
  • 1
  • 13

1 Answers1

1

I do not know how your code is, but what you can do is depending on the platform, import the library or not. Something like this would be:

if (Platform.OS == 'android') {
  firebase = require('react-native-firebase');
}

(this would not work with import)

Another thing that I do not recommend at all, but it would work, is to link firebase to iOS so that it does not launch an error, and when using the library, you can limit it depending on the platform. Like this:

if (Platform.OS == 'android') {
  const notificationsOpen = await firebase.notifications().getInitialNotification()
}
  • Moving back to require from import ? Is it good idea? I want to know in such cases where we might use some packages only for android or ios which might break other. How should we handle these kind of scenarios in a good way. – santosh Dec 13 '18 at 00:35
  • This is on the react-native oficial documentation const Component = Platform.select({ ios: () => require('ComponentIOS'), android: () => require('ComponentAndroid'), })(); https://facebook.github.io/react-native/docs/platform-specific-code I don't think is a terrible idea. (sorry for the dalay responding) – Julian Bonomini Dec 18 '18 at 14:20