Last active
August 29, 2015 14:03
-
-
Save jonalmeida/27bee72b9015d45434e8 to your computer and use it in GitHub Desktop.
What's the correct way to use inDatabase: within an async networking call?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) sendPostData:(NSDictionary *)data withDbIndexArray:(NSMutableArray *)dbIndexArray { | |
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; | |
manager.requestSerializer = [AFJSONRequestSerializer serializer]; | |
[manager POST:[_urlEndpoint absoluteString] parameters:data success:^(AFHTTPRequestOperation *operation, id responseObject) { | |
NSLog(@"JSON: %@", responseObject); | |
[_dbQueue inDatabase:^(FMDatabase *db) { | |
for (int i=0; i < dbIndexArray.count; i++) { | |
NSLog(@"Removing event at index: %@", dbIndexArray[i]); | |
[_db removeEventWithId:[[dbIndexArray objectAtIndex:i] longLongValue]]; | |
[dbIndexArray removeObjectAtIndex:i]; | |
} | |
}]; | |
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
NSLog(@"Error: %@", error); | |
//Add event to queue | |
}]; | |
// [dbIndexArray removeAllObjects]; | |
} | |
// SO: http://stackoverflow.com/questions/24719913/whats-the-correct-way-to-use-indatabase-within-an-async-networking-call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment