iOS应用程序处于后台模式时如何接收数据 [英] How to receiving data when the iOS app is in background mode

查看:81
本文介绍了iOS应用程序处于后台模式时如何接收数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xamarin.Forms中有iOS应用程序开发人员.当它处于最小化/后台模式时,我想接收来自服务器的请求并希望在iOS应用中执行该请求.我已经使用过Info.plist中可用的背景模式"选项,例如音频,Airplay和画中画","IP语音",背景获取",背景处理",但是对我来说不起作用.>

如果上面有任何想法,请帮助我解决.

预先感谢

Vivek

解决方案

看看

If anyone have ideas above for this, then Kindly help me to resolve.

Thanks in advance,

Vivek

解决方案

Having a look at Performing Tasks During DidEnterBackground .

In addition to making a long-running task background-safe, registration can be used to kick off tasks as an application is being put in the background. iOS provides an event method in the AppDelegate class called DidEnterBackground that can be used to save application state, save user data, and encrypt sensitive content before an application enters the background. An application has approximately five seconds to return from this method or it will get terminated. Therefore, cleanup tasks that might take more than five seconds to complete can be called from inside the DidEnterBackground method. These tasks must be invoked on a separate thread.

The process is nearly identical to that of registering a long-running task. The following code snippet illustrates this in action:

public override void DidEnterBackground (UIApplication application) {
  nint taskID = UIApplication.SharedApplication.BeginBackgroundTask( () => {});
  new Task ( () => {
    DoWork();
    UIApplication.SharedApplication.EndBackgroundTask(taskID);
  }).Start();
}

You can do something in DoWork method . By the way , I think apple not recommanding to work as a service to receive data . Generally , this background task is designed to deal with not finished transfering data , such as download or upload data .

这篇关于iOS应用程序处于后台模式时如何接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆