【问题标题】:How to call back on the foreground a background application如何在前台回调后台应用程序
【发布时间】: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


【解决方案1】:

在没有用户交互的情况下仅接收通知就将应用从后台移动到前台是不可能可能的。

点击通知将使您的应用从后台/已终止状态转到前台。

在接到电话时将应用从后台/已终止状态转移到前台是一种特殊情况。 Apple 允许使用 PushKitCallKit 来实现 VoIP 通知。

【讨论】:

    猜你喜欢
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    相关资源
    最近更新 更多