0

I got this error after i call the schedule method on localNotifications plugin.

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,
        }
    });
}
}

app.module.ts

// ....

import {LocalNotifications} from "@ionic-native/local-notifications/ngx";

@NgModule({
    // ....
    providers: [
        LocalNotifications,
    ]
})
export class AppModule {
}

package.json

{
//....
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/core": "~4.18.0",
"@ionic-native/local-notifications": "^5.0.0",
"@ionic-native/splash-screen": "~4.18.0",
"@ionic-native/status-bar": "~4.18.0",
"@ionic/storage": "^2.2.0",
"cordova-android": "^7.1.4",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-ionic-keyboard": "^2.1.3",
"cordova-plugin-ionic-webview": "^2.3.1",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"laravel-echo": "^1.5.2",
"pusher-js": "^4.3.1",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26"
},
"devDependencies": {
  "@ionic/app-scripts": "3.2.1",
  "typescript": "~2.6.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
  "cordova-plugin-whitelist": {},
  "cordova-plugin-statusbar": {},
  "cordova-plugin-device": {},
  "cordova-plugin-splashscreen": {},
  "cordova-plugin-ionic-webview": {
    "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
  },
  "cordova-plugin-ionic-keyboard": {},
  "cordova-plugin-local-notification": {}
},
"platforms": [
  "android"
]
}
}

config.xml

<plugin name="cordova-plugin-whitelist" spec="1.3.3" />
<plugin name="cordova-plugin-statusbar" spec="2.4.2" />
<plugin name="cordova-plugin-device" spec="2.0.2" />
<plugin name="cordova-plugin-splashscreen" spec="5.0.2" />
<plugin name="cordova-plugin-ionic-webview" spec="^2.0.0" />
<plugin name="cordova-plugin-ionic-keyboard" spec="^2.0.5" />
<engine name="android" spec="^7.1.4" />
<plugin name="cordova-plugin-local-notification" spec="~0.9.0-beta.3" />

Here is the error

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.

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

1
  • This is because of Ionic Have updated all the Plugin so I suggest using the lower version of that plugin .! if your current version 4.5.0 or something then you have to downgrade it with 4.3.2 or something. Jan 26, 2019 at 4:29

1 Answer 1

0

Unfortunately, you can not use @ionic-native on a browser

import {LocalNotifications} from "@ionic-native/local-notifications/ngx";

You can only run this on real device or simulators.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.