How to use beginBackgroundTaskWithExpirationHandler for already running task in iOS

前端 未结 6 1516
悲哀的现实
悲哀的现实 2020-11-28 03:10

In my app, I am uploading images to server from iPhone. While sync if user press home button, App will close.

I want app must be running in background till sync fini

6条回答
  •  时光说笑
    2020-11-28 04:15

    I used below code for background task handler:

    __block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
    
        NSLog(@"Background Time:%f",[[UIApplication sharedApplication] backgroundTimeRemaining]);
    
        [[UIApplication sharedApplication] endBackgroundTask:backgroundTaskIdentifier];
    
        backgroundTaskIdentifier = UIBackgroundTaskInvalid;
    }];
    

提交回复
热议问题