我正在开发一个药丸提醒应用程序,该应用程序需要设置药丸提醒功能。 我需要做的是-
我正在使用的库-
https://www.npmjs.com/package/react-native-push-notification
https://www.npmjs.com/package/react-native-background-job
https://www.npmjs.com/package/react-native-sqlite-storage
我已经实现了运行良好的后台进程
import BackgroundJob from 'react-native-background-job';
import SQLite from 'react-native-sqlite-storage';
import PushNotification from 'react-native-push-notification';
//this is the function is getting invoked in background
const pushNoti = () => {
var db = SQLite.openDatabase({ name: "MedCare.db", createFromLocation: 1 }, this.okCallback, this.errorCallback);
db.transaction((tx) => {
tx.executeSql('SELECT * FROM reminders', [], (tx, results) => {
var len = results.rows.length;
if(len > 0){
PushNotification.localNotification({
title: "Its time to take you Pills",
});
}
});
});
}
const backgroundJob = {
jobKey: "myPillReminders",
job: () => pushNoti()
};
BackgroundJob.register(backgroundJob);
export defalt class Reminder extends Component {
componentDidMount() {
var backgroundSchedule = {
jobKey: "myPillReminders",
period: 5000,
exact: true,
allowExecutionInForeground: true
}
BackgroundJob.schedule(backgroundSchedule);
}
}