I have implemented both BGAppRefreshTaskRequest & BGProcessingTaskRequest. I use the AppRefresh for data refresh on the client and small dB updates using RESTful APIs running on an AWS EC2 instance running Django. Users of my iOS app cannot rely on access to the internet when it is in use, so I must queue them to run in background when they are near a WiFi network. The BGAppRefreshTaskRequests to the host are made using NSURLSessionDownloadTasks, as according to Apple Documentation DataTasks are not supported in BGTaskSchedule.
I use ProccessingTask to upload a .jpg file to AWS S3. From the iOS device I execute a HTTP GET NSURLRequest to the host, which returns a dictionary that includes the S3 url, the S3 signature, etc. Per instructions from AWS's web site I create a multipart/form-data NSMutableURLRequest with a boundary string.
I then form a NSURLSessionUploadTask setting the URL and HTTP POST as a multipart/form-data NSMutableURLRequest with a boundary string. I check the response from AWS S3 using the URLSession:session task:didCompleteWithError NSURLSessionTaskDelegate. In analyzing the NSURLResponse it is clear that the system executes a repeat of the NSURLSessionDownloadTask rather than the NSURLSessionUploadTask. There is no response from the AWS S3 host, not even a returned error message.
So, my questions are:
- Is NSURLSessionUploadTask allowed with BGTaskSchedule? If not, should I use NSURLSessionDownloadTask with multipart/form-data to upload a file?
- If NSURLSessionUploadTask is allowed, what could be causing the iOS System to repeat a previous NSURLSessionDownloadTask rather than the file upload?
Prior to POSTing the NSURLSessionUploadTask I cancel any remaining NSURLSesstionTasks on the session.
The application is written in Objective C as it uses a C++ library of OpenCV.
Thank you, Eric
So here is the answer to my own question... I found it more reliable to use NSURLSessionDownloadTask for the purpose of uploading a file to AWS S3. While I remember reading in the "docs" that one could not use NSURLSessionDataTask when operating in background using BGTaskSchedule. I do not recall reading that one could not use NSURLSessionUploadTask. But, Indeed that seems to be the case.... I hope this helps someone else out there.