Skip to content

Instantly share code, notes, and snippets.

@jwhitehorn
Created January 4, 2018 04:15
Show Gist options
  • Save jwhitehorn/cd07f5a8996e457e350542b670358855 to your computer and use it in GitHub Desktop.
Save jwhitehorn/cd07f5a8996e457e350542b670358855 to your computer and use it in GitHub Desktop.
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
NSString *url = @"http://localhost:5000/api/updates/";
if(checksum){
url = [NSString stringWithFormat:@"%@?checksum=%@", url, checksum];
}
[request setURL:[NSURL URLWithString:url]];
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *err) {
NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
if (statusCode == 304) {
//no database update available
return;
}else if(statusCode == 200){
//updated database
if(initialSync){
[data writeToFile:@"database.db" atomically:YES];
}else{
[data writeToFile:@"updated.db" atomically:YES];
}
}
}] resume];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment