Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

on press localNotificaton don't work on android #2188

Closed
IsmetGlumcevic opened this issue Nov 3, 2021 · 6 comments
Closed

on press localNotificaton don't work on android #2188

IsmetGlumcevic opened this issue Nov 3, 2021 · 6 comments
Labels

Comments

@IsmetGlumcevic
Copy link

IsmetGlumcevic commented Nov 3, 2021

When calling localNotificationSchedule in context provider it works, when calling localNotificationSchedule onPress inside component it doesn't work on android. Ios work well.

MacBook air m1
react-native: 0.64
react-native-push-notification: 8.1.1
react-native-community/push-notification-ios: 1.10.1

index.js

   PushNotification.configure({
         onRegister: function (token) {
             console.log('TOKEN:', token);
         },
         onNotification: function (notification) {
            console.log('onnn', notification);
             notification.finish(PushNotificationIOS.FetchResult.NoData);
      },

  permissions: {
    alert: true,
    badge: true,
   sound: true,
   },
  popInitialNotification: true,
   requestPermissions: Platform.OS === 'ios',
  });
  PushNotification.createChannel(
  {
    channelId: 'local-notifications', // (required)
   channelName: 'Local-notifications channel', // (required)
   channelDescription: 'A channel to categorise your notifications', // (optional) default: undefined.
   soundName: 'default', // (optional) See `soundName` parameter of `localNotification` function
   importance: Importance.HIGH, 
   vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
   },
    created => console.log(`createChannel returned '${created}'`), 
    );`

Contex provider:

   useEffect(() => {
   PushNotification.localNotificationSchedule({
   id: '12333',
   channelId: 'local-notifications',
   title: 'Hat er sein Ziel erreicht 1',
   message: 'poruka',
    repeatType: 'minute',
   date: new Date(),
   });
  }, []);

component

 const setupNotification = (id, mess, name) => {
      PushNotification.localNotificationSchedule({
       id: id,
       channelId: `local-notifications`,
        title: name,
        message: mess,
       repeatType: 'minute',
         date: new Date(),
    });
  };

      <TouchableOpacity
              style={FormStyles.button}
              onPress={() => savePlane()}>
              <Text style={FormStyles.buttonText}>Einen Plan machen</Text>
     </TouchableOpacity>
@Dallas62
Copy link
Collaborator

Dallas62 commented Nov 3, 2021

Hi @IsmetGlumcevic
Your exemple is not complete, there is no call of setupNotification.
Since it's working in useEffect, I suggest you to check again your code, probably undefined parameters
Regards

@IsmetGlumcevic
Copy link
Author

I have id: '45id-45rr-33hf-34wd', which format can I put in id? I try with dot, comma.... There is function:

 let newId;
 id.split('').map((item, index) => {
  if (id.length - 1 > index) {
    newId += item.charCodeAt() + ',';
  } else {
    newId += item.charCodeAt();
  }
 });

@Dallas62
Copy link
Collaborator

Dallas62 commented Nov 9, 2021

The fornat/type is described in the readme.

@trindadematheus
Copy link

here dont working too

onPress call:

async function handleComplete() {
  console.log('test')
  PushNotification.localNotification({
    channelId: 'default-channel',
    title: 'testnotify',
    message: 'test'
  })
}

my config:

PushNotification.configure({
  permissions: {
    alert: true,
    badge: true,
    sound: true,
  },
  requestPermissions: false,
});

@marcosfreitas
Copy link

@IsmetGlumcevic did you found a solution?

Copy link

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.

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

No branches or pull requests

4 participants