skip to Main Content

Hello I have created a new 17.1 ReactNative app and have incorporated OneSignal.

According to the example it should subscribe but it does not.

I am also testing this on a physical device.

This runs, no errors and i get the prompt the first time to allow notifications.

But the user is not subscribed.

I tried adding

OneSignal.sendTag('my app id', true);

but got the error sendTag is undefined

my code looks like

const App = () => {

 // Remove this method to stop OneSignal Debugging
 OneSignal.Debug.setLogLevel(LogLevel.Verbose);

 // OneSignal Initialization
 OneSignal.initialize("ONESIGNAL_APP_ID");

 // requestPermission will show the native iOS or Android notification permission prompt.
 // We recommend removing the following code and instead using an In-App Message to prompt for notification permission
 OneSignal.Notifications.requestPermission(true);

 // Method for listening for notification clicks
 OneSignal.Notifications.addEventListener('click', (event) => {
   console.log('OneSignal: notification clicked:', event);
 });

 const isDarkMode = useColorScheme() === 'dark';
 const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
 };

 return (
   <SafeAreaView style={backgroundStyle}>
      <StatusBar
         barStyle={isDarkMode ? 'light-content' : 'dark-content'}
         backgroundColor={backgroundStyle.backgroundColor}
      />
    <ScrollView
    contentInsetAdjustmentBehavior="automatic"
    style={backgroundStyle}>
    <Header />
    <View
      style={{
        backgroundColor: isDarkMode ? Colors.black : Colors.white,
      }}>
      <Button
        title="Press me"
        onPress={subscribe}
      />
      <LearnMoreLinks />
    </View>
    </ScrollView>
   </SafeAreaView>
 );
 };

Thanks for any help

2

Answers


  1. I use

        OneSignal.setAppId("ONESIGNAL_APP_ID")
    

    instead of

        OneSignal.initialize("ONESIGNAL_APP_ID")
    

    To assign a user / phone to the OneSignal application. Maybe this could help!

    Login or Signup to reply.
  2. you need run in useEffect like

    useEffect(()=>{
        // Remove this method to stop OneSignal Debugging
        OneSignal.Debug.setLogLevel(LogLevel.Verbose);
    
        // OneSignal Initialization
        OneSignal.initialize("ONESIGNAL_APP_ID");
    
        // requestPermission will show the native iOS or Android notification permission prompt.
        // We recommend removing the following code and instead using an In-App Message to prompt for notification permission
        OneSignal.Notifications.requestPermission(true);
    
        // Method for listening for notification clicks
        OneSignal.Notifications.addEventListener('click', (event) => {
            console.log('OneSignal: notification clicked:', event);
        });
    },[])
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search