Am I missing something? Cause I want the app to receive the response and do some stuffs even if it's in the background. Here's what I use in my app:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = /*generate the parameters*/;
NSURL *filePath = [NSURL fileURLWithPath:@"imageName.png"];
[manager POST:@"http://example.com/resources.json" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:filePath name:@"image" error:nil];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
//debug here
//Told the app to stop the Loading View, save response to DB
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
//debug here
//Told the app to stop the Loading View and try again sometimes
}];
It's my bad. I forgot to tell the app to keep running when it enter background. I added these codes into my project:
UIBackgroundTaskIdentifier backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
}];
And when the app go into background:
[[UIApplicatioz sharedApplication] endBackgroundTask:backgroundTask];