diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index b70293495..5f5d141ec 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -395,17 +395,22 @@ namespace llmr { namespace platform { + + class Request { + public: + int16_t identifier; + std::string original_url; + }; + void restart() { [[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil]; } - Request request_http(std::string url, std::function background_function, std::function foreground_callback) + Request *request_http(std::string url, std::function background_function, std::function foreground_callback) { NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@(url.c_str())] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - [[NSNotificationCenter defaultCenter] postNotificationName:MBXUpdateActivityNotification object:nil]; - Response res; if ( ! error && [response isKindOfClass:[NSHTTPURLResponse class]]) @@ -424,22 +429,20 @@ namespace llmr [task resume]; - [[NSNotificationCenter defaultCenter] postNotificationName:MBXUpdateActivityNotification object:nil]; + Request *req = new Request(); - Request req; - - req.identifier = task.taskIdentifier; - req.original_url = url; + req->identifier = task.taskIdentifier; + req->original_url = url; return req; } - void cancel_request_http(Request request) + void cancel_request_http(Request *request) { [[NSURLSession sharedSession] getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) { for (NSURLSessionDownloadTask *task in downloadTasks) - if (task.taskIdentifier == request.identifier) + if (task.taskIdentifier == request->identifier) return [task cancel]; }]; }