提问人:guirms 提问时间:7/9/2022 更新时间:7/9/2022 访问量:202
电容器的背景模式无法正常工作
Background mode on capacitor does not work properly
问:
我尝试在应用程序处于后台且互联网连接已更改时显示通知。当我打开应用程序时,一切正常,但是当我关闭应用程序(在后台)时,没有任何反应
import { Platform } from '@ionic/angular';
import { BaseServiceService } from './../services/base-service/base-service.service';
import { LocalNotifications, LocalNotificationSchema } from '@capacitor/local-notifications';
import { Component, OnInit } from '@angular/core';
import { BackgroundMode } from '@ionic-native/background-mode/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
notificationsDelayInSeconds = '';
constructor(private backgroundMode: BackgroundMode,
public baseService: BaseServiceService,
private platform: Platform) {
platform.ready().then(() => {
backgroundMode.enable();
backgroundMode.on('activate').subscribe(() => {
window.addEventListener('offline', () => {
this.baseService.scheduleNotification();
});
});
});
}
}
答: 暂无答案
评论