I want's to upload big file(video) from my application while application is in Background mode. I am using AFNetworking Library. Application is running from 3 min but after that it kill all the activity.
Below code i use in application.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
AFHTTPRequestOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {} failure:^(AFHTTPRequestOperation *operation, NSError *error) {}];
[operation setUploadProgressBlock:^(NSUInteger __unused bytesWritten,
long long totalBytesWritten,
long long totalBytesExpectedToWrite) {}];
[operation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{}];
[manager.operationQueue addOperation:operation];
For uploading large files you have to use AFURLSessionManager class and configure its object with NSURLSessionConfiguration.
Your code to upload large file using AFNetworking would be as following:
You also have set the value of the NSURLSessionConfiguration object’s sessionSendsLaunchEvents property to YES and implement application:handleEventsForBackgroundURLSession:completionHandler: in your app delegate class so that when your file will be uploaded completely then the system will its call this delegate method to wake up your app. So you can know that the upload process is done and can perform any further task.
You can get better idea about using NSURLSession and NSURLSessionConfiguration to download and upload files while the app is in background from below 2 links so please refer these links to implement it.
https://developer.apple.com/library/prerelease/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
http://w3facility.org/question/how-to-work-with-large-file-uploads-in-ios/