Cordova-plugin-local-notifications: Local Notification trigger not working in 0.9.0_beta.3

Created on 19 May 2018  路  6Comments  路  Source: katzer/cordova-plugin-local-notifications

WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

Provide a general summary of the issue.
Initializing an array called notification with parameter below:
let hr = 10;
let mn = 30;
let notification = {
id: alarmId,
title: AlarmTitle,
text: AlarmText,
trigger: { every: { hour: hr, minute: mn} }
};
this.localNotifications.schedule(notification);

Error is coming :
[ts]
Argument of type '{ id: any; title: any; text: any; trigger: { every: { hour: string; minute: any; }; }; }' is not assignable to parameter of type 'ILocalNotification | ILocalNotification[]'.
Type '{ id: any; title: any; text: any; trigger: { every: { hour: string; minute: any; }; }; }' is not assignable to type 'ILocalNotification[]'.
Property 'length' is missing in type '{ id: any; title: any; text: any; trigger: { every: { hour: string; minute: any; }; }; }'.

Your Environment

  • Plugin version: 0.9.0_beta.3
  • Platform: android
  • OS version: oreo (8.0.0)
  • Device manufacturer / model: Mi A1
  • Cordova version (cordova -v): 7.1.0
  • Cordova platform version (cordova platform ls):
    -> Installed platforms:
    -> android 6.3.0
  • Available platforms:
    -> blackberry10 ~3.8.0 (deprecated)
    -> browser ~5.0.0
    -> ios ~4.5.1
    -> osx ~4.0.1
    -> ubuntu ~4.3.4 (deprecated)
    -> webos ~3.7.0
    -> windows ~5.0.0
    -> www ^3.12.0
  • Plugin config:
    > cordova plugin ls
    -> com-badrit-base64 0.2.0 "Base64"
    -> cordova-android-support-gradle-release 1.3.0 "cordova-android-support-gradle-release"
    -> cordova-base64-to-gallery 4.1.3 "base64ToGallery"
    -> cordova-plugin-android-permissions 1.0.0 "Permissions"
    -> cordova-plugin-badge 0.8.7 "Badge"
    -> cordova-plugin-calendar 5.0.0 "Calendar"
    -> cordova-plugin-camera 4.0.4-dev "Camera"
    -> cordova-plugin-device 1.1.4 "Device"
    -> cordova-plugin-facebook4 1.9.1 "Facebook Connect"
    -> cordova-plugin-file 5.0.0 "File"
    -> cordova-plugin-file-transfer 1.7.0 "File Transfer"
    -> cordova-plugin-firebase 1.0.0 "Google Firebase Plugin"
    -> cordova-plugin-geolocation 4.0.1 "Geolocation"
    -> cordova-plugin-googleplus 5.1.1 "Google SignIn"
    -> cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview"
    -> cordova-plugin-local-notification 0.9.0-beta.3 "LocalNotification"
    -> cordova-plugin-sim 1.3.3 "SIM"
    -> cordova-plugin-speechrecognition 1.1.2 "Speech Recognition"
    -> cordova-plugin-splashscreen 4.0.3 "Splashscreen"
    -> cordova-plugin-whitelist 1.3.1 "Whitelist"
    -> cordova-plugin-x-socialsharing 5.2.1 "SocialSharing"
    -> cordova-plugin-youtube-video-player 1.0.6 "CordovaYoutubeVideoPlayer"
    -> cordova-sms-plugin 0.1.11 "Cordova SMS Plugin"
    -> cordova-sqlite-storage 2.1.2 "Cordova sqlite storage plugin"
    -> cordova-wheel-selector-plugin 1.0.0 "Cordova Wheel Selector Plugin"
    -> es6-promise-plugin 4.1.0 "Promise"
    -> ionic-plugin-keyboard 2.2.1 "Keyboard"
    -> phonegap-plugin-barcodescanner 7.0.2 "BarcodeScanner"
  • Ionic Version (if using Ionic)
    -> @ionic/cli-utils : 1.19.0
    -> ionic (Ionic CLI) : 3.19.0

    Expected Behavior

    trigger parameter for scheduling notification is not working at all.
    _Tell us what should happen_

  • Previously i was using local notification 0.8.5 after upgrading my android sdk 0,8.5 is not working, so i have upgraded local notification from 0.8.5 to 0.9.0_beta.3 and now trigger is not working, actions is working fine.

_What were you trying to do?_

I wanted to set the notification at specific time but after setting up time from time picker , notification comes instantly when i use action parameter but for trigger i am getting error

aaalrm

Most helpful comment

@bilelmoulahi 's answer got me to get the code working again. However, I had to slightly change the code due to typescript errors. So, my working version looks like

cordova.plugins['notification'].local.schedule({
      text: 'Test notifucation',
      trigger: {in: 2, unit: 'hour'},
    });

NOTE: cordova.plugins.notification had to changed to cordova.plugins['notification']

Ionic:

   ionic (Ionic CLI)             : 4.10.2 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.0.1
   @angular-devkit/build-angular : 0.12.4
   @angular-devkit/schematics    : 7.2.4
   @angular/cli                  : 7.2.4
   @ionic/angular-toolkit        : 1.3.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 6 other plugins)

System:

   ios-deploy : 1.9.4
   ios-sim    : 7.0.0
   NodeJS     : v8.10.0 (/usr/local/bin/node)
   npm        : 6.5.0
   OS         : macOS Mojave
   Xcode      : Xcode 10.1 Build version 10B61

All 6 comments

Any joy?

@markterrill - any solution for this error?

The plugin version you are using is not compatible yet with Ionic Native (see Readme file). The ionic wrapper is not part of this plugin. So you should schedule your notification the way it is indicated in the readme file.
Instead of using : this.localnotifications.schedule({..})
try :
cordova.plugins.notification.local.schedule({
...
});

@bilelmoulahi - Thanks you , it's working now :-)

@bilelmoulahi 's answer got me to get the code working again. However, I had to slightly change the code due to typescript errors. So, my working version looks like

cordova.plugins['notification'].local.schedule({
      text: 'Test notifucation',
      trigger: {in: 2, unit: 'hour'},
    });

NOTE: cordova.plugins.notification had to changed to cordova.plugins['notification']

Ionic:

   ionic (Ionic CLI)             : 4.10.2 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.0.1
   @angular-devkit/build-angular : 0.12.4
   @angular-devkit/schematics    : 7.2.4
   @angular/cli                  : 7.2.4
   @ionic/angular-toolkit        : 1.3.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 6 other plugins)

System:

   ios-deploy : 1.9.4
   ios-sim    : 7.0.0
   NodeJS     : v8.10.0 (/usr/local/bin/node)
   npm        : 6.5.0
   OS         : macOS Mojave
   Xcode      : Xcode 10.1 Build version 10B61

@sameera207 thank you for your solution. this works for me.

Was this page helpful?
0 / 5 - 0 ratings