I spent 2 days and I think I need help. Of course, I tried to search on stackOverflow, but could not solve the problem.
My application uploads files (from 2 MB to 100 MB).
I use the background transfer service (ios7)
when the user clicks the button, I start the download as shown below (immediately he presses the "home" button):
NSURLSessionConfiguration * backgroundConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:self.url];
self.session = [NSURLSession sessionWithConfiguration: backgroundConfig delegate:self delegateQueue: [NSOperationQueue mainQueue]];
self.downloadTask =[ self.session downloadTaskWithURL:url];
[self.downloadTask resume];
The delegate method works well for me:
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
I also installed:
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler {
NSLog(@"<<<<<<<<< Save completionHandler >>>>>>>>>>>>>>");
self.backgroundSessionCompletionHandler = completionHandler;
}
-(void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
{
NSLog(@"Background URL session %@ finished events.\n", session);
AppDelegate * delegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];
if(delegate.backgroundSessionCompletionHandler)
{
void (^handler)() = delegate.backgroundSessionCompletionHandler;
handler();
}
}
in AppDelegate.h
I get the block property:
@property (copy) void (^backgroundSessionCompletionHandler)();
I actually followed this tut: http://code.tutsplus.com/tutorials/ios-7-sdk-background-transfer-service--mobile-20595
My problem is that sometimes I upload a file, and sometimes not. only part of the file is present in the file system.
handleEventsForBackgroundURLSession, !
- ?