summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-07-05 17:37:55 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-07-18 22:04:33 -0700
commit1bc4f0e0273d6be24de56512fd52a147ea74f9e1 (patch)
tree140d24c3fd8df21459cba11c1748aa2a87936196 /platform/darwin
parentd9aa812c474ae8fe85fbb6a27f10538033d38276 (diff)
downloadqtlocation-mapboxgl-1bc4f0e0273d6be24de56512fd52a147ea74f9e1.tar.gz
[ios, macos] Offline storage size API
Added a property to MGLOfflineStorage that indicates the disk space occupied by all cached and offline resources. Fixes #5580.
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLOfflineStorage.h8
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm13
-rw-r--r--platform/darwin/test/MGLOfflineStorageTests.m4
3 files changed, 25 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLOfflineStorage.h b/platform/darwin/src/MGLOfflineStorage.h
index 20cc521f2e..211135f84f 100644
--- a/platform/darwin/src/MGLOfflineStorage.h
+++ b/platform/darwin/src/MGLOfflineStorage.h
@@ -217,6 +217,14 @@ typedef void (^MGLOfflinePackRemovalCompletionHandler)(NSError * _Nullable error
*/
- (void)setMaximumAllowedMapboxTiles:(uint64_t)maximumCount;
+/**
+ The cumulative size, measured in bytes, of all downloaded resources on disk.
+
+ The returned value includes all resources, including tiles, whether downloaded
+ as part of an offline pack or due to caching during normal use of `MGLMapView`.
+ */
+@property (nonatomic, readonly) unsigned long long countOfBytesCompleted;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm
index dd15920eab..dab870ea3b 100644
--- a/platform/darwin/src/MGLOfflineStorage.mm
+++ b/platform/darwin/src/MGLOfflineStorage.mm
@@ -275,6 +275,19 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
_mbglFileSource->setOfflineMapboxTileCountLimit(maximumCount);
}
+#pragma mark -
+
+- (unsigned long long)countOfBytesCompleted {
+ NSURL *cacheURL = [[self class] cacheURLIncludingSubdirectory:YES];
+ NSString *cachePath = cacheURL.path;
+ if (!cachePath) {
+ return 0;
+ }
+
+ NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:cachePath error:NULL];
+ return attributes.fileSize;
+}
+
#pragma mark MGLOfflinePackDelegate methods
- (void)offlinePack:(MGLOfflinePack *)pack progressDidChange:(__unused MGLOfflinePackProgress)progress {
diff --git a/platform/darwin/test/MGLOfflineStorageTests.m b/platform/darwin/test/MGLOfflineStorageTests.m
index e2346c5f61..e44bd06e3d 100644
--- a/platform/darwin/test/MGLOfflineStorageTests.m
+++ b/platform/darwin/test/MGLOfflineStorageTests.m
@@ -144,4 +144,8 @@
XCTAssertEqual([MGLOfflineStorage sharedOfflineStorage].packs.count, countOfPacks - 1, @"Removed pack should have been removed from the canonical collection of packs owned by the shared offline storage object. This assertion can fail if this test is run before -testAAALoadPacks or -testAddPack.");
}
+- (void)testCountOfBytesCompleted {
+ XCTAssertGreaterThan([MGLOfflineStorage sharedOfflineStorage].countOfBytesCompleted, 0);
+}
+
@end