В моем приложении Ioni c 4 я пытался вводить локальные уведомления периодически или ежедневно. Уведомление работает нормально с текстом, введенным как данные, но я хочу связать файл json, хранящийся в папке assets / data или на нашем веб-сервере. Я не знаю, как это сделать. Ниже приведен код: I wi sh, чтобы получить несколько строк кодов, которые будут вставлены вместо mydata: с примером строки URL.
import { Component } from '@angular/core';
import { LocalNotifications, ELocalNotificationTriggerUnit } from '@ionic-native/local-notifications/ngx';
import { ToastController, Platform, AlertController } from '@ionic/angular';
import * as moment from 'moment';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
mySegment = 'segment2';
date = moment().toISOString();
message: string;
scedules: any;
scheduled = [];
sankalpam: { id: number; title: string; detail: string; date: string; };
constructor(private localNotifications: LocalNotifications,
public toastController: ToastController,
private plt: Platform,
private alertCtrl: AlertController ) {
this.plt.ready().then(() => {
this.localNotifications.on('click').subscribe(res =>{
console.log('click:', res);
let msg = res.data ? res.data.mydata : '';
this.showAlert(res.title, res.text, msg);
});
this.localNotifications.on('trigger').subscribe(res =>{
console.log('trigger:', res);
let msg = res.data ? res.data.mydata : '';
this.showAlert(res.title, res.text, msg);
});
});
}
scheduleNotification(){
this.localNotifications.schedule({
id: 1,
title: 'Welcome',
text: 'Dr.NVS Welcomes you!',
data: { mydata: 'Thank you so much for using Sri Paranthaman Panchangam App'},
trigger: {in: 5, unit:ELocalNotificationTriggerUnit.SECOND},
// foreground: true;
});
}
recurringNotification(){
this.localNotifications.schedule({
id: 22,
title: 'Recurring',
text: 'Let us get your feedback!',
attachments: ['assets/img/paranthaman.png'],
data: { mydata: this.fakeData}, //here I wish to link data from json incrimented ID
trigger: {every: ELocalNotificationTriggerUnit.MINUTE},
// foreground: true;
});
}
repeatingDaily(){
this.localNotifications.schedule({
id: 42,
title: 'Namaste!',
text: 'இன்றைய விசேஷம்:',
// data: { mydata: 'Thank you so much for using Sri Paranthaman Panchangam App'},
trigger: {every: {hour: 12, minute:1}},
// foreground: true;
});
}
getAll(){
this.localNotifications.getAll().then(res =>
{this.scheduled = res;}
);
}
}
}