@@ -2,6 +2,8 @@
|
||||
#define LLMR_PLATFORM_IOS
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
@@ -18,6 +20,19 @@ void restart(void *obj);
|
||||
// Then, call map.tileLoaded(tile); or map.tileFailed(tile); in the main thread.
|
||||
void request(void *obj, std::shared_ptr<Tile> tile);
|
||||
|
||||
|
||||
struct Response {
|
||||
Response(int16_t code, const char *body, size_t length)
|
||||
: code(code),
|
||||
body(body),
|
||||
length(length) {}
|
||||
int16_t code;
|
||||
const char *body;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
void request_http(std::string url, std::function<void(const Response&)> func);
|
||||
|
||||
// Returns a relative timestamp in seconds. This value must be monotonic.
|
||||
double time();
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
last_click(-1),
|
||||
settings(),
|
||||
map(settings) {
|
||||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
if (!glfwInit()) {
|
||||
@@ -238,7 +238,7 @@ void request(void *, Tile::Ptr tile) {
|
||||
NSData * data,
|
||||
NSError * error) {
|
||||
if (error == nil) {
|
||||
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
|
||||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
|
||||
int code = [httpResponse statusCode];
|
||||
|
||||
if (code == 200) {
|
||||
@@ -261,6 +261,44 @@ void request(void *, Tile::Ptr tile) {
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
void request_http(std::string url, std::function<void(const Response&)> func) {
|
||||
NSMutableURLRequest *urlRequest = [NSMutableURLRequest
|
||||
requestWithURL:[NSURL
|
||||
URLWithString:[NSString
|
||||
stringWithUTF8String:url.c_str()]]];
|
||||
|
||||
if (!queue) {
|
||||
queue = [[NSOperationQueue alloc] init];
|
||||
}
|
||||
|
||||
[NSURLConnection
|
||||
sendAsynchronousRequest:urlRequest
|
||||
queue:queue
|
||||
completionHandler: ^ (NSURLResponse* response, NSData* data, NSError* error) {
|
||||
if (error == nil) {
|
||||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
|
||||
dispatch_async(dispatch_get_main_queue(), ^ {
|
||||
func({
|
||||
[httpResponse statusCode],
|
||||
(const char *)[data bytes],
|
||||
[data length]
|
||||
});
|
||||
});
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), ^ {
|
||||
func({
|
||||
-1,
|
||||
0,
|
||||
0
|
||||
});
|
||||
});
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
|
||||
double time() {
|
||||
return glfwGetTime();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user