Posts

Post not yet marked as solved
2 Replies
388 Views
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.
Posted Last updated
.
Post not yet marked as solved
5 Replies
1.9k Views
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.
Posted Last updated
.
Post not yet marked as solved
0 Replies
467 Views
Hello. I'm supporting one application which can download bunch of files (20-150mb) in background. This flow working fine, but some errors happening. This application also has good logging system and is in production for a long time. Sometimes I get logs from users and see next error:NSPOSIXErrorDomain, Code: 2 "No such file or directory". Investigating this problem, I found next stuff.This error appearing when folder 'Caches/com.apple.nsurlsessiond/[APP_ID]' suddenly clearing while app's session downloading files.It's quite easy reproduce under debugger (because app reinstalling in new folder after each run). Another way to reproduce this bug (more "realistic") - install app, begin download files, connect device to Mac and using some software (for example iExplorer) - go to app and clear Cache directory. But its possible because I install app by myself (as developer). User who downloads app from store unable do this.I read documentation and found this: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW1"In iOS 5.0 and later, the system may delete the Caches directory on rare occasions when the system is very low on disk space. This will never occur while an app is running." At first I suggested that system will not clear cache while it downloading files, but logging explicitly show me that I'm wrong. So I have one question here: Is exist some way to simulate current situation (clearing caches for installed apps) on real device ? I tried to fill all space on my deivce, shedule donwloading and go away from app - but in this case I got only another posix error - "not enough free space" (I not remember exact code and description) and my device lagged a little.
Posted Last updated
.