0

I'm developing an app in React Native and wanted to receive notifications in the app using Onesignal and Firebase, but I'm getting an error, I've already looked in the documentation and apparently it's correct to use.

follows the error code:

  useEffect(()=>{

    OneSignal.init("7c7b85c7-3bd2-48e3-8c75-02835cb223c8");

    OneSignal.addEventListener('opened', this.onOpened);

    return () => OneSignal.removeEventListener('opened', this.onOpened);

  }, []);

function onOpened(openResult){
  console.log('Message: ', openResult.notification.payload.body);
  console.log('openResult: ', openResult);
}

Error:

enter image description here

TypeError: react_native_onesignal__WEBPACK_IMPORTED_MODULE_4__.default.init is not a function
(anonymous function)
C:/Projeto/AppText/App.js:11
   8 | 
   9 | useEffect(()=>{
  10 | 
> 11 |   OneSignal.init("7c7b85c7-3bd2-48e3-8c75-02835cb223c8");
  12 |   ^    
  13 |   OneSignal.addEventListener('opened', this.onOpened);
  14 | 

1 Answers1

0

Which version of react-native-onesignal are you using? From OneSignal official docs for React Native Setup, you can call OneSignal.setAppId(<ONESIGNAL_APP_ID>) for initialization instead of OneSignal.init().


Directly from OneSignal docs

//OneSignal Init Code
OneSignal.setLogLevel(6, 0);
OneSignal.setAppId("YOUR-ONESIGNAL-APP-ID");
//END OneSignal Init Code
Ziwon
  • 589
  • 6
  • 15