ionic local notifications TypeError: Object(…) is not a function
See original GitHub issueWARNING: IF YOU IGNORE THIS TEMPLATE, WE’LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!
Provide a general summary of the issue. I got this error after i call the schedule method on localNotifications plugin.
Your Environment
- Plugin version: ~0.9.0-beta.3
- Platform: Windows x64
- OS version: 10
- Device manufacturer / model: Lenovo Z50-70
- Cordova version (
cordova -v
): 8.1.2 - Cordova platform version (
cordova platform ls
): Installed platforms: android 7.1.4 - Plugin config: no config
- Ionic Version (if using Ionic): 3.9.2
Expected Behavior
It should show me something like this in the console Ionic Native: tried calling StatusBar.styleDefault, but Cordova is not available. Make sure to a) run in a real device or simulator and b) include cordova.js in your index.html
like when trying to use StatusBar in the browser.
Actual Behavior
Uncaught TypeError: Object(...) is not a function at LocalNotifications.schedule (index.js:49) at HomePage.webpackJsonp.76.HomePage.launchNotification (home.ts:76) at home.ts:49 at PrivateChannel.Dispatcher.emit (pusher.js:1596) at PrivateChannel.Channel.handleEvent (pusher.js:3238) at pusher.js:136 at ConnectionManager.Dispatcher.emit (pusher.js:1596) at message (pusher.js:8168) at Connection.Dispatcher.emit (pusher.js:1596) at message (pusher.js:2984) I tried to update @ionic-native and i got the same error, but at the startup of the application.
Steps to Reproduce
- ionic cordova plugin add cordova-plugin-local-notification
- npm install @ionic-native/local-notifications
- add it to the app.module.ts providers from “@ionic-native/local-notifications/ngx”
- use it somewhere and call it’s schedule method like this:
this.localNotifications.schedule({ title: 'Nouvelle reservation', text:
Réservation No ${reservationCode}, data: { reservationId: reservationId, } });
Context
I want to send a notification when a reservation comes : just like this: `import {Component} from ‘@angular/core’; import {NavController} from ‘ionic-angular’; import {SocketsProvider} from “…/…/providers/sockets/sockets”; import {LocalNotifications} from “@ionic-native/local-notifications/ngx”;
@Component({ selector: ‘page-home’, templateUrl: ‘home.html’ }) export class HomePage {
constructor(public navCtrl: NavController, private socket: SocketsProvider, private localNotifications: LocalNotifications) { }
ionViewDidLoad() { this.socket.get().listen(‘ReservationGuideAssigned’, notification => { console.log(notification); this.data.incrementNotificationsCount(1); this.launchNotification(notification.reservation_id, notification.reservation_code); }); }
private launchNotification(reservationId, reservationCode) {
this.localNotifications.schedule({
title: ‘Nouvelle reservation’,
text: Réservation No ${reservationCode}
,
data: {
reservationId: reservationId,
}
});
}
}`
Debug logs
there is just the console which shown above.
More information
I also tried to work directly with cordova, with code like this :
cordova.plugins.notification.local.schedule(…) but cordova is unknown in the browser, so the application crashes.
please help me, I need to work with ionic native, so that i can test the other components of the application without being blocked by cordova.
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top GitHub Comments
Please check version in package.json of your local notification if it was 5.0.0 then delete lcal notification inside from node-modules and then changed package.json to 4.7.0 and then run npm install.
I had face this issue this works for me.
Im also facing this issue