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

Better documentation for cancelLocalNotifications() on Android #259

Closed
danleveille opened this issue Nov 1, 2016 · 8 comments
Closed

Better documentation for cancelLocalNotifications() on Android #259

danleveille opened this issue Nov 1, 2016 · 8 comments
Labels

Comments

@danleveille
Copy link

The documentation states that userInfo is iOS only, however, it states that you can use a userInfo dictionary as an argument for cancelLocalNotifications().

Could someone whose more familiar with this library update the documentation to clarify:

  • What does the argument for cancelLocalNotifications actually do (if anything) on Android?
  • How do you cancel individual scheduled local notifications on Android? (What parameters can you use to match notifications?)
@kennethpdev
Copy link

kennethpdev commented Jan 16, 2017

I'm having a problem with cancelLocalNotifications as well so I made a PR to just simply remove a notification using its ID #336 .

@sticknor
Copy link

Hi,
I was able to finally find success with this cancelLocalNotifications method.

The README leads us to believe that the following will work for android:
PushNotification.localNotificationSchedule({ userInfo: { id: '123'} });
PushNotification.cancelLocalNotifications({ id: '123' });

But it does not....

Instead, do this:
PushNotification.localNotificationSchedule({ id: '123' });
PushNotification.cancelLocalNotifications({ id: '123' });

@kennethpdev
Copy link

I tried this PushNotification.cancelLocalNotifications({ id: '123' }); but nothin works. Still can't remove a specific notification. So I end up doing the PR #336

@j-nolan
Copy link
Contributor

j-nolan commented Mar 23, 2017

@sticknor 's solution did the trick for me (Android). Thanks!

I'd like to add that the key we pass through the details object must be called id:

// Does NOT work
PushNotification.localNotificationSchedule({ key: '123' }); // key, or anything else than id
PushNotification.cancelLocalNotifications({ key: '123' });

// Works
PushNotification.localNotificationSchedule({ id: '123' }); // id
PushNotification.cancelLocalNotifications({ id: '123' });

I think the documentation for this method should avoid the keyword userInfo because it suggests the matching will be performed using the userInfo.id property of existing notifications. Moreover, users can be mislead into believing any key can be used for matching. In reality only the id property can be used for matching.

If that makes sense I'd be happy to open a PR to change it. @npomfret

@npomfret
Copy link
Contributor

Yeah, lost of people find the readme a bit confusing - if you think you can improve please do

@KatSick
Copy link

KatSick commented May 1, 2017

Confirm it working. But only with string type of property ID

@GantMan
Copy link
Contributor

GantMan commented Jun 11, 2017

Given I was in a situation where there were no give unique ids, and I didn't understand the 2 ways of cancelling for iOS and Android, I hope this helps others looking at this like:

#336 and #371

Add/remove local notifications:
image

And that helper I'm using is here:

image

@github-actions
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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants