Skip to content

Instantly share code, notes, and snippets.

@herzi
Created March 21, 2014 19:18
Show Gist options
  • Save herzi/9693931 to your computer and use it in GitHub Desktop.
Save herzi/9693931 to your computer and use it in GitHub Desktop.
NSURLSession* session; // wie du an die kommst, weißt du ja jetzt
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/"]];
[request setValue:@"<ETag vom letzten Mal>" forHTTPHeaderField:@"If-None-Match"];
[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (![response isKindOfClass:[NSHTTPURLResponse class]]) {
error = [NSError errorWithDomain:@"FIXME" code:0 userInfo:@{@"unexpectedType": [[response class] description]}];
}
NSHTTPURLResponse* http = (NSHTTPURLResponse*)response;
if (http.statusCode == 304) {
// keine änderung
return;
} else if (http.statusCode != 200) {
// fehlerbehandlung
return;
}
if (error) {
// fehlerbehandlung
return;
}
// antwort parsen
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment