【发布时间】:2020-05-22 05:41:41
【问题描述】:
我有一个发送本地通知的 ionic cordova 应用程序。我想要本地通知
或触发应用程序进入前台的后台任务(可能使用带有 .moveToForeground() 的 @ionic-native/background-mode/ngx)。接到电话时,whatsapp 和 Skype 会做一些事情。
目前,当我在本地通知循环内调用函数 .moveToForeground() 时,什么也没发生。
任何有关如何进行的指示将不胜感激。
谢谢
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { NavigationExtras } from '@angular/router';
import { StorageService, Item } from './services/storage.service';
import { AuthenticationService } from './services/Authentication.service';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
import {BackgroundMode} from "@ionic-native/background-mode/ngx";
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private storageService: StorageService,
private authenticationService: AuthenticationService,
private localNotifications: LocalNotifications,
private backgroundMode: BackgroundMode
) {
this.initializeApp();
this.backgroundMode.enable();
setInterval(() =>{
this.groupNotif()
}, 19000);
}
groupNotif() {
this.localNotifications.schedule([
{ id: 0, title: 'Design team meeting' },
{ id: 1, summary: 'me@gmail.com', group: 'email', groupSummary: true },
{ id: 2, title: 'Please take all my money', group: 'email' },
{ id: 3, title: 'A question regarding this plugin', group: 'email' },
{ id: 4, title: 'Wellcome back home', group: 'email' }
]);
this.backgroundMode.unlock();
this.backgroundMode.moveToForeground();
}
【问题讨论】:
-
抱歉有问题...这个例子确实有效
标签: android cordova ionic-framework