How can I solve this error. (onesignal + React Native + Android)

Problem

Wanted to make an app for push notifications .
I did the installation following the documentation of OneSignal.
But unfortunately this is returning me an error:

:error:

TypeError: _reactNativeOnesignal.default.init is not a function. (In '_reactNativeOnesignal.default.init("My-id-OS")', '_reactNativeOnesignal.default.init' is undefined)

:App.js:

import OneSignal from 'react-native-onesignal';
import React, { Component } from 'react'

export default class App extends Component {
  constructor(properties) {
    super(properties);
    OneSignal.init("My-id-Onesignal");

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

  componentWillUnmount() {
    OneSignal.removeEventListener('opened', this.onOpened);
  }

  onOpened(openResult) {
    console.log('Message: ', openResult.notification.payload.body);
    console.log('openResult: ', openResult);
  }
  render(){
    return (
    <>
      
    </>
  );
  }
  
};

:app / build.gradle:
Just the changes...[...].

apply plugin: "com.android.application"

import com.android.build.OutputFile
buildscript {
    repositories {
        maven {
            url("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath("gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.10")
    }
}

apply plugin: "com.onesignal.androidsdk.onesignal-gradle-plugin"


:Notes and versions:

React-Native 0.63.4 .
Gradle 7.0.
I've tried running in expo but returns the same error.
Follow tutorial I followed: https://www.youtube.com/watch?v=U1l8phUHG58 .

Author: william silva, 2021-01-20

1 answers

Solved ,I did everything from scratch and following the scratch the documentation, repository link: https://github.com/williamanjo/MobileProject

  • I did not understand the why of giving error the .init being that in the video worked out , at least I managed to solve my problem using the documentation code. - if anyone knows how to fix the mistake of .init, just for study .
 0
Author: william silva, 2021-02-02 13:03:57