pushy/pushy-react-native

Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference

Closed this issue · 3 comments

@eggli @pushy Firebase crashlytics has detected this crash on android. Every user is facing this crash. I am using following versions:
"pushy-react-native": "^1.0.29",
"react-native": "0.70.5",

Screenshot 2023-03-27 at 11 55 03 AM

pushy commented

Hi @faisalur-rehman,
Thanks for creating this issue. We'd be glad to assist.

Where are you invoking Pushy.register()? Is it inside componentDidMount or somewhere else? Please move it to your componentDidMount and it should resolve the issue.

@pushy I am already invoking Pushy.Register inside a useEffect like this:

const registerPushyToken = async () => {
    Pushy.register()
      .then(async deviceToken => {
        dispatch(savePushyDeviceToken(deviceToken));
      })
      .catch(err => {
        console.error('err', err);
      });
  };
  useEffect(() => {
    registerPushyToken();
  }, []);

There is some other code that is being rendered outside the component:

Pushy.toggleInAppBanner(true);

Pushy.setNotificationListener(async data => {
  var payload = {
    title: 'Sensight Notification',
    message: data.message || '...',
  };
  EventRegister.emit('myCustomEvent', JSON.parse(data?.message));
  if (data.message) {
    try {
      payload = JSON.parse(data.message);
    } catch (error) {}
  }

  if (Platform.OS === 'android') {
    Pushy.notify(payload.title, payload.message, data);
  }
  Pushy.setBadge && Pushy.setBadge(0);
});
pushy commented

Hi @faisalur-rehman,
Thanks for your patience and for your response.

This issue has now been fixed in the latest version of the Pushy React Native Android SDK.

Please import version 1.0.19 of the Pushy React Native Android SDK by updating the following dependency in your android/app/build.gradle, within the dependencies {} declaration:

// Pushy SDK for React Native Android
implementation 'me.pushy:sdk-react-native:1.0.19'

Then, re-build and re-run your app, and the issue will be resolved. We apologize for any inconvenience caused by this issue.