iOS: Issues with background uploading large files - ios

I have an app that records and uploads large files ( up to 5gigs each )
After the recordings are done the user triggers an action to begin the file uploads.
The uploads are registered for background processing so they continue if the phone goes asleep.
I issues I am running into:
Random memory crashes on some files over 4 gigs
Unable to initiate a background upload while the app is already suspended.
So if user records a file between 4-5gigs the app will randomly crash while uploading. Multiple 5 gig files uploading at the same time also increases the chance of crashing.
We currently upload the files in sequence but ran into issue #2 from my list. If the user records multiple 5 gigs files, and puts the phone asleep, only the the first file will upload and the user has to reopen the app for the next file to begin processing.
I have attempted to use BackgroundTasks to see if it can trigger an upload but the background task never fires and I've read the only attempts to fire the background task if it thinks the user is about to use the phone.
I also tried using the urlSessionDidFinishEvents callback on uploadTask. But it never seemed to fire or at least it can't be used to call an API request.
Anyone have advice on initating background file uploads for large files?

I think the problem is that you are likely reaching system resource limits. The system will eject your binary when this occurs; they are called Jetsam events. I suggest you trigger a sysdiagnose event on your device (differs per device - usually pressing volume up, down, and side buttons together).
Then recover the logs from Settings > Privacy > Analytics and Improvements > Analytics Data
The file names begin with sysdiagnose_YEAR.MONTH.DAY_*.
After you copy the files over to your Mac (using the Share button in the iOS UI) you can then look at specifically what is being breached.
Please update your question with specific log information thus retrieved.
Lastly, it is worth implementing applicationDidReceiveMemoryWarning: since your app is probably using a lot of memory during such processing.

Related

Can we backup Files and Photos in terminated state

Since there are many places on the Internet talking about Background Fetch in terminated state, some are saying that iOS does not allow anything in that period except working with notifications, location services etc.
Can anyone please give us a final conclusion about this topic, whether the iOS app can work when terminated and what are the limits?
What I'm specifically interested in is file backup. I want to make specific folders in Files periodically (for example each 6h) check if files in it are changed, and if they did, make an API call which will update those changed files on the server. The user should be able to choose which folders he wants. Or for example Photos app, if user gives permission, could we backup the photos from time to time as it works on Google Photos?
These two resources are confusing me a bit, like they are contradictory:
https://www.hackingwithswift.com/example-code/system/how-to-run-code-when-your-app-is-terminated
https://developer.apple.com/documentation/backgroundtasks/bgprocessingtaskrequest
On the first one it says we can run some code when the app is not running for 30 secs, but another says we can execute even longer tasks.

React-native - How to keep fetch file uploading when terminate app(closing by home button) or change other app?

I am making camera ios app(just after take a photo and upload) by using react-native.
However, I have a one problem. When I upload a photo directly to server, (most of photo size is over 1MB~2MB) this fetch post time is a little slow so that whenever I terminate app(by using home button) or use other app(changing), fetch post is failed and disconnected. (If I wait for response in app active status, It is easy to success.)
How to keep the file upload fetching during app closing status?
Maybe, Should I use react-native-background-fetch? I am a little complicated in this library.
Thanks to read :).

0 bytes uploaded of file stored on cloud service via <input type=file> on iOS

I'm having trouble working out why some uploads to our server from iOS result in empty files. The upload page is a simple form using POST and enctype as multipart/form-data.
The problem only seems to arise when the user:
Is using iOS
Attempts to upload a file from a cloud service (currently iCloud or Dropbox) even if the file is the version on their local system
Leaves a period of time between selecting the file (via a <input type=file> button) and initiating the upload, roughly about 30sec to 1min.
I'm not sure if there is a timeout issue with the connection to the file, and if so, whether this is a bug or a security feature. If the user selects their file and initiates the upload within this time, the file uploads successfully.
Uploads from the 'true' local system (eg. outside any cloud folders) upload fine, even after any delay. The file size and file type seem to be irrelevant.
I'm aware Dropbox have a 'Chooser' system, which forwards a link instead of the file, however in testing, a Dropbox file will still upload successfully provided the user does so within a short time.
The form that handles the upload is rather large with many options, so typically a user will spend some time between selecting the file and initiating the upload.
The problem does not occur on Android or OSX desktop platforms.
I have also tested using an independent online uploader, namely http://checkfiletype.com/ and performed the same test, and the same thing happens:
result after pressing 'upload' straight away,
and
result after short a delay and then pressing 'upload'.
I'm not sure where to go from here, most Googling only turns up results about uploading TO cloud platforms, instead of from them. Am I missing something?
Update: This appears to be no longer be the case with the release of iOS 15.4. The updates page contains under 'bug fixes':
Photos and videos may not sync to iCloud Photo Library
Whilst it doesn't describe the bug directly, it appears the dev teams have actually made adjustments to the chooser/file system. What a shame it took several years.

Batch Downloading files using NSURLSession with file integrity on iOS

We have an application that downloads user contents. Our files could be big ones and usually our users download as batch. Our users having different troubles on download that described below. We want to refactor whole download process and possible use a library for that. We would like your opinion on problems and solutions.
Current Process:
We have list of items, which users can download, each item consists of a single file or multiple files (users don’t aware of that). User can initiate download of an item by pressing the “download button” on the list, and we support concurrent download of items. Remember each item can have multiple files or single file. We also need to show progress of download for items individually. We are using NSURLConnection to download files it was developed since iOS 4.
Problems:
During download if there is a network glitch or some unknown reasons
download gets stuck.
During download lost some data of the file
Having trouble to download in the background (We have to keep screen
awake for example to make download continue etc. since it was
developed on iOS 4)
There is no file integrity check when download is finished
Resume Download
What we need:
Download big files as batch, usually 10 to 50 files, size around 10
to 200 MB of each file
Pause when there is a connection problem (lost, troubled/deadly
slow), auto resume when connection is back
Download in the background (app suspended or closed)
Resume download in background when app is crashed or terminated
Pause, Cancel of Downloads by User
Integrity check when download is complete
Integrity check while download is in progress (on downloaded parts),
auto re-download bad parts before download completes
Getting progress info (list of downloads, downloaded ones, percentage
of download, estimated time of complete, download speed etc.)
Multiple threads to fast download
Support from iOS 7 to Later
In which solution we can make sure each of our needs covered? How can we achieve this?
Ok it can be simply achieved by using NSUrlSession (NSURLSessionDataTask, NSURLSessionDownloadTask) - it will solve all your downloading problems(multiple threads to fast download(concurrent downloading ),resume, pause, cancel and etc.) including background downloads . Also it supports completion block which can be helpful for file integrity check. To check for Internet connection in order to pause or resume downloads you can use Reachability library.
If you wish to use third-party library I stronglly recommend you to use AFNetWorking (everything from your requirements can be done by this library)-->https://github.com/AFNetworking/AFNetworking
Also, this tutorial can be helpfull for your needs - http://www.appcoda.com/background-transfer-service-ios7/

iOS / PhoneGap app fails to download remote images/video via REST API after 60secs - why is it timing out?

We have built an in-house Enterprise iPad2+ application that connects to a Drupal CMS, where content (text/images/video) is being delivered to the app via a REST API.
When the user launches the app for the first time, they are prompted to download the content over WIFI network. We are experiencing content failing to download inconsistently i.e. sometimes 60 images fail to download; other times 20 images fail. Since we've added video into the download mix, the content is failing even more often.
Server details:
Windows server
IIS7.5
PHP 5.3
MYSQL5.1
App details:
Require.js: provides JavaScript file and module loading
Backbone.js: provides a frontend JavaScript application framework
Cordova (v2.7.0): Used to provide an environment to run on iOS
Raphael.js: For procedural graphics and animations
jQuery and plugins: For Dom manipulation, animations and interactions
Bootstrap: Base framework for HTML mark-up
Download process is as follows:
User launches app and is prompted to download content
Download begins
The app now makes AJAX call to REST API to fetch content
Upon a successful fetch, the REST API delivers an array of content (text/images/video) - max video filesize 11mb
Content is delivered synchronously
We can add logic to keep retrying upon failure, but this could result in an indefinite loop. The content download size is approx. 50mb, over WIFI.
Our testing:
We have tried from 3 different locations in the world: SA, UK and US and similar issues.
We've tested a 300mb download from the same server, on the same iPad and it downloads fine
QUESTION:
Can anyone tell us why this would be failing?
Could the problem be with a Drupal configuration issue we're missing?
UPDATE 25 August:
We have done some more research and it seems the problem may be a result of iOS Safari timing out at 60secs, and then everything fails after that that to download - see here: http://www.sencha.com/forum/showthread.php?111231-iOS-Safari-Mobile-AJAX-timeout
Has anyone else come across this issue?
We have tried downloading over LAN, and that is 100% fine. WIFI is the issue.
We have tried refreshing the download script after x seconds and resetting the timeout counter. We've tried to detect if a download has failed and to continue retrying it.
Stumped at this point...
UPDATED SOLUTION 28 August:
UPDATED SOLUTION: we have fixed the problem. The issue fundamentally lies in the fact that iOS Safari times out at 60secs. Why? We have no idea... What we were doing was fetching the full list files to download, and then downloading them synchronously. What happened at 60secs, is the download times out and we were losing our file list. What we did to resolve this, is we saved the files not downloaded list at 60secs, then started the download process again with this new list, and repeated this process until all files successfully downloaded.

Resources