react-native-onesignal icon indicating copy to clipboard operation
react-native-onesignal copied to clipboard

[question]: Trying to catch error on promptForPushNotificationsWithUserResponse

Open ajouve opened this issue 2 years ago • 4 comments

How can we help?

Hello,

I have the exact same error for some of my users https://github.com/OneSignal/react-native-onesignal/issues/1449

I tried to do something like that to prevent it

export async function init() {
  try {
    OneSignal.setAppId('xxx');

    try {
      // https://github.com/OneSignal/react-native-onesignal/issues/1449
      OneSignal.promptForPushNotificationsWithUserResponse();
    } catch (error) {
      if (Platform.OS !== 'android') {
        throw error;
      }
      await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
      );
    }

  } catch (error) {
    logError(error);
  }
}

But the error is not catch, is it normal ?

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

ajouve avatar Mar 31 '23 06:03 ajouve

Hi @ajouve, thanks for reaching out! Based on the other issue you linked, it sounds like you are getting a crash when calling OneSignal.promptForPushNotificationsWithUserResponse(), so you implemented PermissionsAndroid as a workaround?

Can you share a bit more about the expected outcome of the code snippet you shared vs. what is happening instead?

Any additional details about your setup would be helpful as well! What version of react-native are you using? What is your current compileSdkVersion?

Thanks!

jennantilla avatar Apr 06 '23 16:04 jennantilla

I am not able to reproduce this issue, I only have the logs threw sentry

RuntimeException
Could not invoke OneSignal.promptForPushNotificationsWithUserResponse

This is my build.gradle

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        supportLibVersion = "28.0.0"

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath 'com.google.gms:google-services:4.3.14'
    }
}

I am using react-native 0.71.2

ajouve avatar Apr 07 '23 08:04 ajouve

@ajouve I've tried the same solution here. Did you solve it?

hkanizawa avatar May 01 '23 12:05 hkanizawa

@hkanizawa Nothing for now

I can not reproduce the issue on my phones, I do not know if it causes a crash

ajouve avatar May 02 '23 14:05 ajouve

Hello everyone! Apologies that this issue has gone stale. Since it has been some time since this issue has seen any discussion, I'll go ahead and close it out.

If this is still a concern for anyone, please @ mention me and we will renew investigation.

We have a new major release update for our React Native SDK that includes many improvements and enhancements. I encourage everyone to upgrade! Please see our migration guide for full details.

Thanks!

jennantilla avatar Apr 30 '24 19:04 jennantilla