diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-02-03 14:53:59 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-02-03 14:53:59 +0100 |
commit | 44a3ffbd575de29f4bc6ab782a9fecff6472f827 (patch) | |
tree | 7b781a83fb0beab3e3f65408cba45c595132a03a /macosx/main.mm | |
parent | 6849c8d576d9197170156b2a17223157ee1b4bef (diff) | |
download | qtlocation-mapboxgl-44a3ffbd575de29f4bc6ab782a9fecff6472f827.tar.gz |
alternative http_request function
Diffstat (limited to 'macosx/main.mm')
-rw-r--r-- | macosx/main.mm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/macosx/main.mm b/macosx/main.mm index 68ebeedc5d..f1b02dabfe 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -248,6 +248,29 @@ void request_http(std::string url, std::function<void(Response&)> func) { }]; } +void request_http(std::string url, std::function<void(Response&)> func, std::function<void()> cb) { + NSMutableURLRequest *urlRequest = [NSMutableURLRequest + requestWithURL:[NSURL + URLWithString:[NSString + stringWithUTF8String:url.c_str()]]]; + + [NSURLConnection + sendAsynchronousRequest:urlRequest + queue:[NSOperationQueue mainQueue] + completionHandler: ^ (NSURLResponse* response, NSData* data, NSError* error) { + Response res; + if (error == nil) { + NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; + res.code = [httpResponse statusCode]; + res.body = { (const char *)[data bytes], [data length] }; + } + + func(res); + dispatch_async(dispatch_get_main_queue(), ^ { + cb(); + }); + }]; +} double time() { |