向服务器发出的HTTP请求在后台模式下无法工作

问题描述 投票:0回答:1

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

 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个回答
0
投票

在iOS上,你不能这样做,正如你所描述的那样。对于安卓系统来说,如果应用程序从内存中移除,应用程序也不会在后台。即使你将保持应用程序在后台,这不是一个好主意,它会消耗你的电池。

如果你的服务器正在操作数据,直到它是可接受的,它可以发送推送通知,为什么它需要等待从手机传入的请求?为什么不在数据准备好的时候直接发送推送呢?如果应用程序决定什么是 "可接受的",也许让应用程序告诉服务器它想要什么,这样服务器就知道什么时候发送推送。

这就是android和iOS的原生应用的工作方式。使用推送通知来管理和实现你的需求。

在后台模式下发送HTTP请求

© www.soinside.com 2019 - 2024. All rights reserved.