diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-03-09 08:36:10 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-03-10 17:08:58 -0800 |
commit | c335847451a850dfcac8c3ea262f4d686115e146 (patch) | |
tree | 788322030ad06299612f7fa4ce326539a07b022e | |
parent | e218728f3ac5f4924615713136a642168d19029b (diff) | |
download | qtlocation-mapboxgl-c335847451a850dfcac8c3ea262f4d686115e146.tar.gz |
[ios, osx] Invalidate task immediately upon removal
-rw-r--r-- | platform/darwin/include/MGLOfflineStorage.h | 9 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage.mm | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/platform/darwin/include/MGLOfflineStorage.h b/platform/darwin/include/MGLOfflineStorage.h index 459371d9f7..4844d9d4a8 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 f2061b4a3f..274cef7688 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); }); } |