What is the best practice to handle HandleEventsForBackgroundURLSession?
Here is scenario:
1. NSURLSession created with background configuration. session identifier(which was used to create the configuration) was saved to local persistent storage.
2. NSURLSessionUploadTask created(from a file). upload task resumed.
3. While uploading, App terminated by the user. at this point the background transfer keeps uploading the data.
4. Background transfer finished upload all data, re-launch the app.
5. App delegate didFinishLaunchingWithOptions is called(in background). Note: HandleEventsForBackgroundURLSession will be called later after handling didFinishLaunchingWithOptions.
At this point(in didFinishLaunchingWithOptions) I observe that an upload session identifier exists in the local persistent storage, therefore I would like to re-associate the session and update it's states.
Is that the best practice?
Shouldn't I wait for the HandleEventsForBackgroundURLSession to be called, save the completion, re-associate the session, collect all the events waiting and call the completion?
But how can I determine if HandleEventsForBackgroundURLSession is about to be called after didFinishLaunchingWithOptions(which is not always the case)?
I've notice that UIApplicationLaunchOptionsURLSessionKey is delivered via didFinishLaunchingWithOptions option dictionary.
Should I relay on that un-documented flag?
Thanks.