0

I'm using OneSignal on my app for push notifications. After follow their tutorial (https://documentation.onesignal.com/docs/react-native-sdk-setup) everything seems to be working on Android. However on IOS I'm getting this error:

enter image description here

I copy the exact same code from OneSignal tutorial:

// Root.js

import React from 'react';
import OneSignal from 'react-native-onesignal';
import { ONESIGNAL_KEY } from '@env';
import { Provider } from 'react-redux';

import { ThemeProvider } from 'styled-components';
import { theme } from 'utils/theme';
import store from 'store';
import App from './App';

class Root extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      isSubscribed: false,
    };
  }

  async componentDidMount() {
    // /* O N E S I G N A L   S E T U P */
    OneSignal.setAppId(ONESIGNAL_KEY);
    OneSignal.setLogLevel(6, 0);
    OneSignal.setRequiresUserPrivacyConsent(false);
    OneSignal.promptForPushNotificationsWithUserResponse((response) => {
      this.OSLog('Prompt response:', response);
      console.log('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);
      console.log({ 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 (
      <Provider store={store}>
        <ThemeProvider theme={theme}>
          <App />
        </ThemeProvider>
      </Provider>
    );
  }
}

export default Root;

If I comment the line this.OSLog('Prompt response:', response); the error disappear on IOS

Any idea what might be causing this error?

Thank you

Mário Prada
  • 141
  • 2
  • 9

1 Answers1

0

Since OSLog is referred to by this, you can - as you did - exchange it with console.log(). It is a local function to the class in App.js