Hello. I'm using NSURLSession (with background configuration) for downloading files. I have couple questions about NSURLSession workflow.
1) Sometimes, in very rare cases I noticed that in callbacks
(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(nullable NSError *)error
(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
task.repsonse / task.originalRequest has nil value. Unfortunately, I can't 100% reproduce it. I suggest that it can depends on some backend configuration or some edge case while file is downloading.
In docs these fields marked as nullable (so seems it's correct behavior), but explanation is very poor.
For example, for originalRequest it says
may be nil if this is a stream task. But I'm not using stream task. I use
[self.session downloadTaskWithURL:someURL];
and task usually contains originalRequest (at least when I created it).
2) In most samples, people (and I'm) using originalRequest as a unique key for tracking process (updating UI, moving downloaded file to documents directory, etc) and task.repsonse for detecting status code. So these fields are critical for proper management.
How to properly handle situation when these fields are nil? Can I just ignore it? Is it safe behavior?
3) Another interesting example which I noticed from different downloader implementations - save source URL and other metadata as task.taskDescription and use it instead of originalRequest in callbacks. Main advantage here that I can fetch tasks after app relaunch using
(void)getTasksWithCompletionHandler:(void (^)(NSArray<NSURLSessionDataTask *> *dataTasks, NSArray<NSURLSessionUploadTask *> *uploadTasks, NSArray<NSURLSessionDownloadTask *> *downloadTasks))completionHandler;
method. Is it a safe approach? I think to it in case when originalRequest is nil.
Post
Replies
Boosts
Views
Activity
Recently I used UIActivityViewController and noticed that it has been changed for iOS13. Now this VC presenting on half of the screen and user be able to open it more or close. It's looking interesting and I tried to reproduce such behavior for regular VC.At first, I thought there is some customization under new iOS13 modal style but looking into documentation/googling did not help.After that I tried to implement UIViewControllerAnimatedTransitioning protocol + UIViewPropertyAnimator. It's working, but the result does not look completely like native UIActivityViewController. It's working very poor - for example, I'm unable to control smooth status bar transition. Or if I need to present another modal VC - seems like I need to reimplement native page sheet animation behavior. So I have a question. Is it possible to duplicate UIActivityViewController animation flow (with dragging for open more/closing, smooth status bar transition etc) using public UIKit API? Maybe I missed something?Thanks in advance.