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

Notification not fired when device is locked or app in background #635

Closed
bwoodlt opened this issue Jan 22, 2018 · 9 comments
Closed

Notification not fired when device is locked or app in background #635

bwoodlt opened this issue Jan 22, 2018 · 9 comments
Labels

Comments

@bwoodlt
Copy link

bwoodlt commented Jan 22, 2018

Hi all,

Have been struggling with this for a few hours. Local push notification not firing when on home screen and when device is locked. This is on iOS.

Anyone been able to solve this issue? Please help a brother.

Thanks all,

@IgorUsoltsev
Copy link

This answer helped me to solve the issue - #17 (comment)

I had to set 'content-available' => 1 property for iOS push notification object, as stated here - https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH4-SW57

This keys forces app to watch for this notification in background mode.

@bwoodlt
Copy link
Author

bwoodlt commented Jan 22, 2018

@IgorUsoltsev did you set 'content-available' inside your PushNotification.LocationNotification({ "content-available" : 1}}?

@bwoodlt
Copy link
Author

bwoodlt commented Jan 23, 2018

Here's my code and setup:

Have got this code in my PushNotification.js file.

  const PushNotification = require('react-native-push-notification');

   PushNotification.configure({

   onNotification: (notification) => {
    if (!notification.userInteraction) {
      PushNotification.setApplicationIconBadgeNumber(0);
    }
    if (notification.foreground) {
      PushNotification.setApplicationIconBadgeNumber(0);
    }

    notification.finish(PushNotificationIOS.FetchResult.NoData);
    },
    popInitialNotification: true,

  requestPermissions: true,
  'content-available': 1
});

And when using, I use like so:

PushNotification.localNotification({
              title,
              message
            });

I also have in my componentDidMount() this bits:

 componentDidMount() {
    AppState.addEventListener('change', (state) => {
      if (state === 'active') {
        PushNotification.popInitialNotification((notification) => {
          if (notification) {
            Alert.alert(notification);
            // onNotification(notification);
          }
        });
        PushNotification.setApplicationIconBadgeNumber(0);
      }
    });

I get notifications when app is in background but not when device is locked or not active. I'm probably missing something..

@IgorUsoltsev
Copy link

@bwoodlt I send them from my backend server. But I guess this could work from local notification as well.

As for your locked/not active device - I didn't meet this issue as I use APN/GCM to send messages. And they come as generic push notifications that you can open anytime and launch app.

@ghost
Copy link

ghost commented Feb 8, 2018

change your 'active' to 'backgroud'

@zhaonian
Copy link

@bwoodlt How did you solve this issue?

@tijp
Copy link

tijp commented Mar 19, 2018

I had the same issue because the 'Do Not Disturb' feature on my iPhone was turned on. When turning that off it worked again.

@vijayapios
Copy link

i also getting same issue, can any one help me out

@github-actions
Copy link

github-actions bot commented Nov 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 5, 2020
@github-actions github-actions bot closed this as completed Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants