Created
September 27, 2011 03:08
-
-
Save hramos/1244223 to your computer and use it in GitHub Desktop.
Parse SDK 0.2.15 is blocking main thread when preparing to upload a PFObject with lots of data. Moving this to a background thread avoids UI freeze
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
// original file: PFRequest.m | |
- (void)buildAndSignPostBody { | |
for (NSString *key in self.command.params) { | |
[self setPostValue:[self.command.params objectForKey:key] forKey:key]; | |
} | |
// This also ensures that posts are not empty, which would break various things | |
[self setPostValue:[NSString stringWithFormat:@"i%@", PARSE_VERSION] forKey:@"v"]; | |
__block NSString *header = nil; | |
/* I'm using DISPATCH_QUEUE_PRIORITY_LOW, as DISPATCH_QUEUE_PRIORITY_BACKGROUND | |
* is not available until 4.3 | |
*/ | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ | |
// Background Thread | |
[self buildPostBody]; | |
header = PF_OAuthorizationHeader([self url], | |
[self requestMethod], | |
[self postBody], | |
APPLICATION_ID, | |
CLIENT_KEY, | |
nil, | |
nil); | |
dispatch_sync(dispatch_get_main_queue(), ^{ | |
// Main Thread | |
[self addRequestHeader:@"Authorization" value:header]; | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment