简体   繁体   English

iOS应用程序处于后台模式时如何接收数据

[英]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.

相关问题 将应用程序发送到后台模式后,如何继续接收数据? - How to keep receiving the data when app is sent to background mode? 当应用程序在iOS中处于后台模式时,无法接收GCM通知 - GCM Notifications not receiving when app is in background mode in iOS Firebase消息传递。 iOS应用在后台模式或关机时未收到通知 - Firebase messaging. iOS app not receiving notifications when in background mode or shut down 当应用程序处于后台模式时,Pebble Watch将数据推送到iOS - Pebble Watch pushing data to iOS when app is in background mode 在后台模式下使用App接收通知 - Receiving Notifications with App in background mode 当需要后台模式访问时,如何在iOS上安全地存储数据? - How to store data securely on iOS when background mode access is required? 应用程序未运行时,iOS后台模式? - iOS background mode when app is not running? 应用程序在后台时未收到通知(iOS react-native) - Not receiving notification when app in background (iOS react-native) 当应用程序处于后台模式时更改tabBar徽章(Swift iOS) - Change tabBar badge when an app is in background mode (swift ios) iOS:Objective -C如何在应用程序处于后台模式时更改推送通知声音有效负载? - iOS:Objective -C How to change push notification sound payload when app in background mode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM