[英]How to receiving data when the iOS app is in background mode
I have iOS app developers in Xamarin.Forms.我在 Xamarin.Forms 中有 iOS 应用程序开发人员。 I want to receive the request (from server) and want to execute it in iOS app, when it is in minimized / background mode.我想接收请求(来自服务器)并希望在 iOS 应用程序中执行它,当它处于最小化/后台模式时。 I have already played with Background Modes option available in Info.plist like "Audio, Airplay and Picture in Picture", "Voice over IP", "Background fetch", "Background Processing" but it didn't work for me.我已经玩过 Info.plist 中可用的背景模式选项,如“音频、播放和画中画”、“IP 语音”、“背景获取”、“背景处理”,但它对我不起作用。
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 .看看在 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. iOS 在 AppDelegate 类中提供了一个名为DidEnterBackground
的事件方法,可用于在应用程序进入后台之前保存应用程序状态、保存用户数据和加密敏感内容。 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.因此,可以从DidEnterBackground
方法内部调用可能需要 5 秒以上才能完成的清理任务。 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 .你可以在DoWork
方法中做一些事情。 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 .通常,此后台任务旨在处理未完成传输的数据,例如下载或上传数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.