ionic local notification error: Uncaught (in promise): TypeError: Object(...) is not a function
ionic local notification error: Uncaught (in promise): TypeError: Object(...) is not a function
我想在我的 ionic project.I 添加本地通知 app.module.ts;
从“@ionic-native/local-notifications/ngx”导入 {LocalNotifications};
并且我在提供商中添加了 LocalNotifications。
也在home.ts我写了这段代码;
sendLocalNotifications() {
this.localNotifications.schedule({
title: 'Local ILocalNotification Example',
text: 'Delayed ILocalNotification',
trigger: {at: new Date(new Date().getTime() + 3600)},
led: 'FF0000',
data: {secret: "asaddad"},
sound: null
});
我还在 home.ts 中定义了导入和构造函数。当我在 android 设备上 运行 我的代码时出现以下错误;
**Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
at LocalNotifications.schedule (vendor.js:92805)
at HomePage.webpackJsonp.328.HomePage.sendLocalNotifications (main.js:2891)
at main.js:2881
at t.invoke (polyfills.js:3)
at Object.onInvoke (vendor.js:5134)
at t.invoke (polyfills.js:3)
at r.run (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (vendor.js:5125)
at c (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (vendor.js:5125)
at t.invokeTask (polyfills.js:3)
at r.runTask (polyfills.js:3)
at o (polyfills.js:3)**
你能帮帮我吗?
如果您使用的是 ionic 3,请访问此 link
https://ionicframework.com/docs/v3/native/local-notifications/
安装 cordova 插件和 npm
$ ionic cordova plugin add cordova-plugin-local-notification
$ npm install --save @ionic-native/local-notifications@4
需要在 app.module.ts 文件中导入
import {LocalNotifications} from '@ionic-native/local-notifications';
在提供程序数组 [app.module.ts 文件]中添加 LocalNotifications
providers: [
StatusBar,
SplashScreen,
ImagePicker,
InAppBrowser,
LoginService,
ConnectivityService,
Network,
GooglePlus,
GoogleServiceProvider,
GoogleMapsKeyProvider,
AppVersion,
BarcodeScanner,
Device,
FCM,
CheckStorageProvider,
Facebook,
Geolocation,
TwitterConnect,
LinkedIn,
File,
Camera,
FileTransfer,
FilePath,
Base64,
{provide: ErrorHandler, useClass: IonicErrorHandler},
LocalNotifications
]
this.localNotifications.requestPermission().then((permission) => {
this.localNotifications.schedule({
id: 0,
text: 'Delayed ILocalNotification',
trigger: {at: date},
foreground: true,
vibrate: true,
led: {color: '#FF00FF', on: 500, off: 500},
data: {mydata: 'My hidden message this is'},
sound: this.setSound(),
});
});
通过将 .mp3 声音文件放在 src/assets/sounds/sound.mp3
来设置声音
setSound() {
if (this.platform.is('android')) {
return 'file://assets/sounds/sound.mp3'
} else {
return 'file://assets/sounds/sound.mp3'
}
}
您可以在订阅方法收到通知后阅读隐藏消息
(可在首页或app.component.ts文件中添加)
if (_platform.is('cordova')) {
this.localNotifications.on('click').subscribe((datas: any) => {
alert(JSON.stringify(datas));
});
}
我想在我的 ionic project.I 添加本地通知 app.module.ts;
从“@ionic-native/local-notifications/ngx”导入 {LocalNotifications};
并且我在提供商中添加了 LocalNotifications。
也在home.ts我写了这段代码;
sendLocalNotifications() {
this.localNotifications.schedule({
title: 'Local ILocalNotification Example',
text: 'Delayed ILocalNotification',
trigger: {at: new Date(new Date().getTime() + 3600)},
led: 'FF0000',
data: {secret: "asaddad"},
sound: null
});
我还在 home.ts 中定义了导入和构造函数。当我在 android 设备上 运行 我的代码时出现以下错误;
**Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
at LocalNotifications.schedule (vendor.js:92805)
at HomePage.webpackJsonp.328.HomePage.sendLocalNotifications (main.js:2891)
at main.js:2881
at t.invoke (polyfills.js:3)
at Object.onInvoke (vendor.js:5134)
at t.invoke (polyfills.js:3)
at r.run (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (vendor.js:5125)
at c (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (vendor.js:5125)
at t.invokeTask (polyfills.js:3)
at r.runTask (polyfills.js:3)
at o (polyfills.js:3)**
你能帮帮我吗?
如果您使用的是 ionic 3,请访问此 link
https://ionicframework.com/docs/v3/native/local-notifications/
安装 cordova 插件和 npm
$ ionic cordova plugin add cordova-plugin-local-notification
$ npm install --save @ionic-native/local-notifications@4
需要在 app.module.ts 文件中导入
import {LocalNotifications} from '@ionic-native/local-notifications';
在提供程序数组 [app.module.ts 文件]中添加 LocalNotifications
providers: [
StatusBar,
SplashScreen,
ImagePicker,
InAppBrowser,
LoginService,
ConnectivityService,
Network,
GooglePlus,
GoogleServiceProvider,
GoogleMapsKeyProvider,
AppVersion,
BarcodeScanner,
Device,
FCM,
CheckStorageProvider,
Facebook,
Geolocation,
TwitterConnect,
LinkedIn,
File,
Camera,
FileTransfer,
FilePath,
Base64,
{provide: ErrorHandler, useClass: IonicErrorHandler},
LocalNotifications
]
this.localNotifications.requestPermission().then((permission) => {
this.localNotifications.schedule({
id: 0,
text: 'Delayed ILocalNotification',
trigger: {at: date},
foreground: true,
vibrate: true,
led: {color: '#FF00FF', on: 500, off: 500},
data: {mydata: 'My hidden message this is'},
sound: this.setSound(),
});
});
通过将 .mp3 声音文件放在 src/assets/sounds/sound.mp3
来设置声音setSound() {
if (this.platform.is('android')) {
return 'file://assets/sounds/sound.mp3'
} else {
return 'file://assets/sounds/sound.mp3'
}
}
您可以在订阅方法收到通知后阅读隐藏消息 (可在首页或app.component.ts文件中添加)
if (_platform.is('cordova')) {
this.localNotifications.on('click').subscribe((datas: any) => {
alert(JSON.stringify(datas));
});
}