cordova 如何在前台回调后台应用程序

ycl3bljg  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(159)

我有一个发送本地通知的ionic cordova应用程序。我希望本地通知或后台任务触发应用程序进入前台(可能使用@ionic-native/background-mode/ngx和.moveToForeground())。这是sapp和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();

  }
epggiuax

epggiuax1#

仅在收到推送通知时,可能在没有用户交互的情况下将应用程序从后台移到前台。
点击通知将使您的应用程序从后台/已删除状态进入前台。
在接到电话时将应用从后台/已删除状态切换到前台是一个特殊情况。Apple允许使用PushKitCallKit进行VoIP通知。

相关问题