When an iOS application goes to the background, are lengthy tasks paused?

后端 未结 3 1796
有刺的猬
有刺的猬 2020-11-27 13:06

Yes, I know if I wish my app to be responsive to users\' multitasking actions, such as switch to another app, I should deal with

- (void)applicationWillResi         


        
3条回答
  •  暖寄归人
    2020-11-27 13:55

    If you are doing some operation which might consume time and you don't want to kill it then you can extend the time for your operation by executing in UIBackground Task i

    {
        UIBackgroundTaskIdentifier  taskId = 0;
        taskId = [application beginBackgroundTaskWithExpirationHandler:^{
            taskId = UIBackgroundTaskInvalid;
        }];
    
    // Execute long process. This process will have 10 mins even if your app goes in background mode.
    
    }
    

    The block argument called "handler" is what will happen when the background task expire (10min). Here is a link to the documentation

提交回复
热议问题