Unhandled promise rejection: TypeError: null is not an object (evaluating 'RNOneSignal.setAppId')]
that error occurs everytime. what i do now? it works on React-native-cli Project. it gives error on Expo-cli
import * as React from "react";
import Home from "./Home"
import OneSignal from "react-native-onesignal";
class App extends React.Component {
async componentDidMount() {
/* O N E S I G N A L S E T U P */
OneSignal.setAppId("bb92b317-9038-4a4c-a52a-e0f3f9b3f163");
// OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
OneSignal.setLogLevel(6, 0);
OneSignal.setRequiresUserPrivacyConsent(false);
OneSignal.promptForPushNotificationsWithUserResponse(response => {
this.OSLog("Prompt response:", response);
});
/* O N E S I G N A L H A N D L E R S */
OneSignal.setNotificationWillShowInForegroundHandler(notifReceivedEvent => {
this.OSLog("OneSignal: notification will show in foreground:", notifReceivedEvent);
let notif = notifReceivedEvent.getNotification();
const button1 = {
text: "Cancel",
onPress: () => { notifReceivedEvent.complete(); },
style: "cancel"
};
const button2 = { text: "Complete", onPress: () => { notifReceivedEvent.complete(notif); } };
Alert.alert("Complete notification?", "Test", [button1, button2], { cancelable: true });
});
OneSignal.setNotificationOpenedHandler(notification => {
this.OSLog("OneSignal: notification opened:", notification);
});
OneSignal.setInAppMessageClickHandler(event => {
this.OSLog("OneSignal IAM clicked:", event);
});
OneSignal.addEmailSubscriptionObserver((event) => {
this.OSLog("OneSignal: email subscription changed: ", event);
});
OneSignal.addSubscriptionObserver(event => {
this.OSLog("OneSignal: subscription changed:", event);
this.setState({ isSubscribed: event.to.isSubscribed })
});
OneSignal.addPermissionObserver(event => {
this.OSLog("OneSignal: permission changed:", event);
});
const deviceState = await OneSignal.getDeviceState();
this.setState({
isSubscribed: deviceState.isSubscribed
});
}
render() {
return (
<Home />
);
}
}
export default App;