diff --git a/platform/darwin/include/MGLOfflineStorage.h b/platform/darwin/include/MGLOfflineStorage.h index 459371d9f..4844d9d4a 100644 --- a/platform/darwin/include/MGLOfflineStorage.h +++ b/platform/darwin/include/MGLOfflineStorage.h @@ -70,8 +70,13 @@ typedef void (^MGLOfflineTaskListingCompletionHandler)(NS_ARRAY_OF(MGLOfflineTas /** Unregisters the given offline task and frees any resources that are no longer - required by any remaining tasks. After this task is removed, it is invalid; any - attempt to interact with it will result in an exception being thrown. + required by any remaining tasks. + + As soon as this method is called on a task, the task becomes invalid; any + attempt to send it a message will result in an exception being thrown. If an + error occurs and the task cannot be removed, do not attempt to reuse the task + object. Instead, use the `-getTasksWithCompletionHandler:` method to obtain a + valid pointer to the task object. @param task The offline task to remove. @param completion The completion handler to call once the task has been diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm index f2061b4a3..274cef768 100644 --- a/platform/darwin/src/MGLOfflineStorage.mm +++ b/platform/darwin/src/MGLOfflineStorage.mm @@ -104,6 +104,7 @@ } - (void)removeTask:(MGLOfflineTask *)task withCompletionHandler:(MGLOfflineTaskRemovalCompletionHandler)completion { + [task invalidate]; self.mbglFileSource->deleteOfflineRegion(std::move(*task.mbglOfflineRegion), [&, task, completion](std::exception_ptr exception) { NSError *error; if (exception) { @@ -113,7 +114,6 @@ } if (completion) { dispatch_async(dispatch_get_main_queue(), [&, task, completion, error](void) { - [task invalidate]; completion(error); }); }