-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[Android] Fix cancelLocalNotifications #371
[Android] Fix cancelLocalNotifications #371
Conversation
Cheers, this is definitely an improvement. It would be nice to eventually have parity between iOS and Android in the canceling interface, but this works for now. |
Does anyone know why the |
@npomfret because it was matching all object keys. We should only be matching ids since you are only supplying the id to cancel a notification. |
I can't see this in the code, i looks right to me. Its looping over the keys in the userInfo object passed in. If they all match then we've found the notification to cancel - which is the same behaviour as iOS. No? |
@npomfret iOS uses the userInfo object to find a match, however userInfo is not available on Android. See here and here Is the cancelLocalNotification feature working for you with the current implementation on Android? I don't think it has ever worked. The objects will never match since you are comparing all the notification attributes |
This iOS UserInfo object is basically just a dictionary. Below the iOS implementation of
|
The userInfo object is just represented as a map in android (and iOS too - it's not a class, it's just a dictionary). So from your js you call something like:
Which get converted into a java Perhaps it's a type problem. Are you passing a string for your id in when it should be an int, or vicer-versa? |
It should be a string and I am passing a string. Ok so this {id: '1234'} ReadableMap object what does it get compared to? |
I've got to suggest you take a look at the code, there's not much to it. The userInfo object get's passed in here. And then it's compared to the each stored notification using the Basically, each stored notification is treated like as a map. Each key of the passed-in Have you tried stepping through in the Android Studio debugger to see if the match method is being called and why it's not matching your parameters? |
Ok so However if it finds this notification object |
Extra keys in the underlying notification should not used in the comparison, same as with the iOS implementation. And as far as I can see they are not. See for yourself: https://github.com/zo0r/react-native-push-notification/blob/master/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationAttributes.java#L137 |
Can you confirm that it works on your end and that you can cancel a notification? My PR is essentially just doing this. So I'm not sure why the match method doesn't work for me. |
Aright, I think i understand why it isn't working. The confusion is with the name - The method that I think you want, which does not exist (yet). And perhaps could/should be added as an android only method, something like:
This will remove an individual alert from the notification centre for android only. I don't see why this can't be added so long as it's clear in the docs that it isn't supported in iOS. |
This is what I am after. But it's ok. If it works on your end as it should then we can close this PR. I'll continue using my fork for now until I'll review this again when I'll upgrade. |
Closing. Lets add an android only clearLocalNotification method |
@npomfret are you going to add this |
I'm afraid I don't have time right now. You could submit a PR if you like? |
Fixes 259, 368, 338