Background execution automatically stops after 3 m

2019-09-10 10:43发布

问题:

I wanted upload photos as background task but background execution stops automatically after 3 minutes.

Code which I have done:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
   UIApplication *app = [UIApplication sharedApplication];

    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    //Stop upload call

    [app endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}];
}}

回答1:

I found that iOS puts strict limits on how long you can run. Specifically:

When you move from the foreground to the background, the limit is currently 3 minutes. When you are resumed in the background, the limit is 30 seconds.

Link referral : https://krumelur.me/2015/11/25/ios-background-transfer-what-about-uploads/

Thanks @feroz for providing the link.