Background downloading even if the phone gets locked

前端 未结 1 1216
春和景丽
春和景丽 2021-01-24 12:17

I am trying to implement an application for iPhone that should simply download some content out of the web. This download is quite big, so I implemented the download as a backgr

相关标签:
1条回答
  • 2021-01-24 13:11

    You need to surround the downloading code with background task block like this:

    UIApplication* app = [UIApplication sharedApplication];
            UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
                //here you need to finish what you are doing evven if you've not finished yet, otherwise your app will be killed
                [app endBackgroundTask:bgTask];
            }];
    
            //here comes your downloading code
    
            [app endBackgroundTask:bgTask];
    

    This will give you 10 minutes(according to some other posts) to execute code in background...

    0 讨论(0)
提交回复
热议问题