Background Task with NSOperation and NSOperationQueue iOS

后端 未结 2 511
谎友^
谎友^ 2021-01-22 02:51

I want to upload some files which should continue even if the application goes into background.

Currently I am retrieving the files from the DB and than adding it to the

相关标签:
2条回答
  • 2021-01-22 03:41

    Why not try doing this? .. I haven't yet tried it out, I'll post an update after attempting this

    UIApplication* application = [UIApplication sharedApplication];
    bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
      // Clean up any unfinished task business by marking where you
      // stopped or ending the task outright.
    
      // Bring up your NSOperation queue instance here and block this thread until it is complete
      [queue waitUntilAllOperationsAreFinished];
    
      [application endBackgroundTask: bgTask];
      bgTask = UIBackgroundTaskInvalid;
    }]; 
    

    also ensure that you have a way to cancel all these long standing operation in the background

     bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
            // Clean up any unfinished task business by marking where you.
            // stopped or ending the task outright.
            [queue cancelAllOperations];
    
            [application endBackgroundTask:endSessionTask];
            bgTask = UIBackgroundTaskInvalid;
        }];
    
    0 讨论(0)
  • 2021-01-22 03:41

    Apple allows background execution if your app follows and satisfy the necessary condition. plese refer here

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