Created
January 4, 2018 04:15
-
-
Save jwhitehorn/cd07f5a8996e457e350542b670358855 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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