I'm having difficulty by uploading to a server from iOS assets library. Successfully I managed to get the photos datas and store them in an array, however I cannot managed to send them to the server in a best way.
I tried the NSOperationQueues, AFNetworking, NSSessionUploadTasks.. I'm aware of them however couldn't get the send them 1 by 1 in a queue to the server. Maybe I did not correctly implemented the functions.
If I tried to send them like
NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
calling it in a thread it's going 1 by 1 however when the app is suspended my connection is failed and it stops sending the photos.
If I tried to send them like
-(void)sendImageUploadOperation:(NSData *)image setURL:(NSURL *)url{
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setTimeoutInterval:600];
NSMutableData *body = [NSMutableData data];
[body appendData:[NSData dataWithData:image]];
[urlRequest setHTTPBody:body];
NSURLSessionConfiguration *sessionConfig =
[NSURLSessionConfiguration backgroundSessionConfiguration:@"com.example.apple-samplecode.BackgroundSession"];
NSURLSession *upLoadSession = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];
NSURLSessionUploadTask *uploadTask = [upLoadSession uploadTaskWithStreamedRequest:urlRequest];
[uploadTask resume];
}
It says : "Terminating app due to uncaught exception 'NSGenericException', reason: 'Upload tasks in background sessions must be from a file " even if I'm not sending the files url , i'm sending the NSData of the image that I processed before.
I'm stuck in the middle of the networking. Please somebody can help me how can I handle this situation. I'm tried to upload images on the foreground and continue in the background as well.And also I'm getting a response from the server if it is successfully added or not. So the response is very important for me and send all the images I selected 1 after another .