Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to navigate app off a notification but getInitialNotification returning null no matter what/ _onRemoteNotification is working properly #169

Open
1 task done
mgoldfi1 opened this issue Aug 12, 2020 · 1 comment

Comments

@mgoldfi1
Copy link

mgoldfi1 commented Aug 12, 2020

Report

Environment

  • Platforms: So far only tested iOS,
  • iOS version: 13.6 and lower

Issues and Steps to Reproduce

  1. Generate push notification
  2. App is either minimized or terminated
  3. User clicks on notification or opens app
  4. getInitialNotification() returning null from promise no matter what

Expected Behavior

I want a way to be able to tell if the notification was clicked on so that I can either direct the navigation to the chat screen or otherwise just open the app normally. Right now, I can only get _onRemoteNotification to be hit, which is not that useful because I only want to navigate the user if they clicked on the notification, not i they got a notification while they were in the app. I can't find any use cases for this but regardless im not hitting the .catch and its returning null every time. There is a chance I'm using this incorrectly but there is barely any documentation so I guess I should ask when exactly is getInitialNotification supposed to be hit?

Actual Behavior

App opens if you click the notification, sometimes onRemoteNotification is hit sometimes it is not.

Function:

getInitialNotification() {
    console.log('hitting function');
    NotificationHub.getInitialNotification()
      .then(res => {
        console.warn(res);
//This returns null every time
        if (res) {
//Never have made it inside this block
          Alert.alert(
            'Get Initial Notification Received',
            'Alert message: ' + res.getMessage(),
            [
              {
                text: 'Dismiss',
                onPress: null,
              },
            ],
          );
        }
      })
      .catch(reason => console.warn('ERROR', reason));
//Have not gotten an error
  }

App.js/ componentDidMount : I attach a listener to appState because i want to get the notification whenever it is brought to foreground. Am I doing this correctly/logically?

  componentDidMount = async () => {
    AppState.addEventListener('change', state => {
      store.dispatch({type: 'CHANGED_STATE', state});
//When state changes I update redux to handle other processes such as data fetching.
      if (state === 'active') {
        this.getInitialNotification();
//Calling method when brought to foreground
      }
    });
    this.requestPermissions()
      .then(x => console.warn(x))
      .catch(err => console.warn(err));
  };
@mgoldfi1
Copy link
Author

To anyone encountering a similar issue:

I realized this problem only occurs in debug/release builds but not distribution builds such as testflight which was very difficult for me to find out and eventually discovered by accident. After updating APNS certs to production and pushing the build to testflight, the getInitialNotification method is being hit on app cold start through a push notification. I don't know much else yet but this is what I have found so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant