если вы используете ionic 3, перейдите по этой ссылке
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.tsfile
import {LocalNotifications} from '@ionic-native/local-notifications';
Добавить LocalNotifications в массиве провайдеров [файл app.module.ts]
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));
});
}