首页 > 解决方案 > 如何让应用程序在后台模式下运行

问题描述

我已经构建了离子应用程序,我需要一种方法来让我的应用程序在后台破坏,我使用设置间隔发送 HTTP 请求但是当我关闭应用程序时它不起作用

  constructor(
              public http: HttpClient,
              public platform: Platform ,
              public navCtrl: NavController, 
              private callLog: CallLog,
              private backgroundMode: BackgroundMode,
              private statusBar : StatusBar,
              private appService: AppServiceProvider,
              private uniqueDeviceID: UniqueDeviceID,
            ) 
          {
            var self= this
            if(this.platform.is('cordova')){
              this.platform.ready().then(()=>{
              this.getDeviceId()
              this.deviceId = localStorage.getItem('DviceId')
              this.callLog.requestReadPermission()
              this.backgroundMode.enable();
              this.statusBar.overlaysWebView(true);
              this.statusBar.styleDefault();
              setInterval(function(){
                self.backgroundMode.enable()
                self.postLogs()
              }, 6000)
            })
          }
          }

标签: ionic3

解决方案


推荐阅读