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

_reactNativePushNotification.default.cancelLocalNotification is not a function #2143

Closed
Degn opened this issue Sep 12, 2021 · 12 comments
Closed
Labels

Comments

@Degn
Copy link

Degn commented Sep 12, 2021

I receive the following error message when I am calling PushNotification.cancelLocalNotification(id):

[TypeError: _reactNativePushNotification.default.cancelLocalNotification is not a function. (In '_reactNativePushNotification.default.cancelLocalNotification(id)', '_reactNativePushNotification.default.cancelLocalNotification' is undefined)]

I am using the following versions:
react-native-push-notification: 8.1.0
react-native: 0.65.0

I expect the function to cancel the scheduled push notification with the specific ID. Instead I receive the error message above. I have tested on both an iOS and Android device with the same result. Other PushNotification functions work fine.

@Degn
Copy link
Author

Degn commented Sep 12, 2021

I have seen the similar open and closed issues regarding this issue and it does not change anything here when I am cleaning the cache

@Dallas62
Copy link
Collaborator

Can you check the version directly in your node_modules ?
There is probably mistake and bugs, but for this issue, I'm 100% it's because of cache.
Regards

@Degn
Copy link
Author

Degn commented Sep 12, 2021

@Dallas62 my package.json is:

{
  "_from": "react-native-push-notification@8.1.0",
  "_id": "react-native-push-notification@8.1.0",
  "_inBundle": false,
  "_integrity": xxx,
  "_location": "/react-native-push-notification",
  "_phantomChildren": {},
  "_requested": {
    "type": "version",
    "registry": true,
    "raw": "react-native-push-notification@8.1.0",
    "name": "react-native-push-notification",
    "escapedName": "react-native-push-notification",
    "rawSpec": "8.1.0",
    "saveSpec": null,
    "fetchSpec": "8.1.0"
  },
  "_requiredBy": [
    "#USER",
    "/"
  ],
  "_resolved": "https://registry.npmjs.org/react-native-push-notification/-/react-native-push-notification-8.1.0.tgz",
  "_shasum": "16bb3755287a005cd8341c48535d9c78856b58b8",
  "_spec": "react-native-push-notification@8.1.0",
  "_where": xxx,
  "author": {
    "name": "zo0r",
    "email": "http://zo0r.me"
  },
  "bugs": {
    "url": "https://github.com/zo0r/react-native-push-notification/issues"
  },
  "bundleDependencies": false,
  "deprecated": false,
  "description": "React Native Local and Remote Notifications",
  "homepage": "https://github.com/zo0r/react-native-push-notification#readme",
  "keywords": [
    "react-component",
    "react-native",
    "ios",
    "android",
    "notifications",
    "push",
    "apns",
    "firebase"
  ],
  "license": "MIT",
  "main": "index.js",
  "name": "react-native-push-notification",
  "peerDependencies": {
    "@react-native-community/push-notification-ios": "^1.10.0",
    "react-native": ">=0.33"
  },
  "repository": {
    "type": "git",
    "url": "git+ssh://git@github.com/zo0r/react-native-push-notification.git"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "version": "8.1.0"
}

@nfmshow
Copy link

nfmshow commented Sep 21, 2021

@Degn, I'm also facing this issue. Were you able to find a solution?

@cynde
Copy link

cynde commented Sep 22, 2021

use cancelLocalNotifications({id: 1})

@nfmshow
Copy link

nfmshow commented Sep 23, 2021

@cynde, thanks. cancelLocalNotifications({ id: 1 }) does not throw an error but it did not cancel my ongoing notification.

I also tried PushNotification.removeDeliveredNotifications([ notificationId ]) but it didn't work too.

@nfmshow
Copy link

nfmshow commented Nov 4, 2021

PushNotification.removeDeliveredNotifications([ notificationId ]) eventually worked for me but I had to ensure that my notificationId is not "1". Other numbers worked fine.

@theneekz
Copy link

theneekz commented Jan 5, 2022

use cancelLocalNotifications({id: 1})

Id must be a string so it should be cancelLocalNotifications({id: "1"})
Even though this is deprecated, this was my solution. Ensure that the id is a string, not a number:

export function cancelLocalNotificationById(id) {
  if (typeof id === 'number') {
    id = id.toString();
  }
  PushNotification.cancelLocalNotifications({ id });
}

@theneekz
Copy link

theneekz commented Jan 5, 2022

use cancelLocalNotifications({id: 1})

Id must be a string so it should be cancelLocalNotifications({id: "1"}) Even though this is deprecated, this was my solution. Ensure that the id is a string, not a number:

export function cancelLocalNotificationById(id) {
  if (typeof id === 'number') {
    id = id.toString();
  }
  PushNotification.cancelLocalNotifications({ id });
}

Can we expect a fix for cancelLocalNotification or should we continue to use the deprecated method @zo0r ?

@Dallas62
Copy link
Collaborator

Dallas62 commented Jan 5, 2022

The state of the repository is in the Readme.
Regards

@Sliimy
Copy link

Sliimy commented Jan 6, 2022

I had the same error, it seems to be an issue with the cache.

I used a previous version with the function cancelLocalNotifications({id:"abc"})

But this method is now deprecated, so I update the package (version 8.1.1) and tried to use cancelLocalNotification("abc")
It didn't work in the first time.

It was due to two things.

First one, the native function was not executed. (Even cleaning the cache and uninstalling/reinstalling the app)
I had to make some random changement in the file /node_modules/react-native-push-notification/component/index.android.js , save it, start the application with an error, and remove my random changement, start the app. And now the native function was executed.
It seems that my application was still using the file from the previous version. The issue #2122 helps me to figure it out.

Second one, the id must be a string of integer, id="abc" did not work anymore but id="123" works.

I hope it will help.

@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

6 participants