【问题标题】:Http request to server not working on background mode对服务器的 Http 请求在后台模式下不起作用
【发布时间】:2020-06-10 06:12:26
【问题描述】:

请按照代码。 HTTP 请求在 ionic 中无法在后台模式下工作。

 this.platform.ready().then(() => {
        this.backgroundMode.setDefaults({
            text: 'Doing heavy tasks.'
        });
        // Enable background mode
        this.backgroundMode.enable();
        // Called when background mode has been activated
        this.backgroundMode.isActive(); // => boolean

        this.backgroundMode.on("activate").subscribe(() => {
            console.log('Print console for background');
            setInterval(function(){
                // http request (post method)
            }, 5000);
        });
    });

【问题讨论】:

    标签: angular ionic-framework ionic4 background-process


    【解决方案1】:

    正如你所描述的,在 iOS 上你不能这样做。对于 android,如果应用程序从内存中删除,该应用程序也不会在后台运行。即使您将应用程序保留在后台,这也不是一个好主意,它会耗尽您的电池电量。

    如果您的服务器正在处理数据直到它可以接受,并且它可以发送推送通知,为什么它需要等待来自电话的传入请求?为什么不在数据准备好时发送推送?如果应用程序决定什么是“可接受的”,也许让应用程序告诉服务器它想要什么,以便服务器知道何时发送推送。

    这就是原生应用在 android 和 iOS 上的工作方式。使用推送通知管理和实现您的要求。

    Send HTTP Requests in Background Mode

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-23
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多