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 .
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…