summaryrefslogtreecommitdiff
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
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.
-rw-r--r--platform/darwin/src/MGLOfflineStorage.h8
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm13
-rw-r--r--platform/darwin/test/MGLOfflineStorageTests.m4
-rw-r--r--platform/ios/CHANGELOG.md1
-rw-r--r--platform/macos/CHANGELOG.md1
5 files changed, 27 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
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md
index 67ba86d098..2df305a213 100644
--- a/platform/ios/CHANGELOG.md
+++ b/platform/ios/CHANGELOG.md
@@ -8,6 +8,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CON
* As the user zooms in, tiles from lower zoom levels are scaled up until tiles for higher zoom levels are loaded. ([#5143](https://github.com/mapbox/mapbox-gl-native/pull/5143))
* Added [quadkey](https://msdn.microsoft.com/en-us/library/bb259689.aspx) support and limited WMS support in raster tile URL templates. ([#5628](https://github.com/mapbox/mapbox-gl-native/pull/5628))
* Fixed an issue causing polyline and polygon annotations to disappear when the zoom level is one less than the maximum zoom level. ([#5418](https://github.com/mapbox/mapbox-gl-native/pull/5418))
+* Added a property to MGLOfflineStorage, `countOfBytesCompleted`, that indicates the disk space occupied by all cached and offline resources. ([#5585](https://github.com/mapbox/mapbox-gl-native/pull/5585))
* The `text-pitch-alignment` property is now supported in stylesheets for improved street label legibility on a tilted map. ([#5288](https://github.com/mapbox/mapbox-gl-native/pull/5288))
* The `icon-text-fit` and `icon-text-fit-padding` properties are now supported in stylesheets, allowing the background of a shield to automatically resize to fit the shield’s text. ([#5334](https://github.com/mapbox/mapbox-gl-native/pull/5334))
* Improved the performance of relocating a non-view-backed point annotation by changing its `coordinate` property. ([#5385](https://github.com/mapbox/mapbox-gl-native/pull/5385))
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md
index a652befb9a..881ccc41e2 100644
--- a/platform/macos/CHANGELOG.md
+++ b/platform/macos/CHANGELOG.md
@@ -8,6 +8,7 @@
* As the user zooms in, tiles from lower zoom levels are scaled up until tiles for higher zoom levels are loaded. ([#5143](https://github.com/mapbox/mapbox-gl-native/pull/5143))
* Added [quadkey](https://msdn.microsoft.com/en-us/library/bb259689.aspx) support and limited WMS support in raster tile URL templates. ([#5628](https://github.com/mapbox/mapbox-gl-native/pull/5628))
* Fixed an issue causing polyline and polygon annotations to disappear when the zoom level is one less than the maximum zoom level. ([#5418](https://github.com/mapbox/mapbox-gl-native/pull/5418))
+* Added a property to MGLOfflineStorage, `countOfBytesCompleted`, that indicates the disk space occupied by all cached and offline resources. ([#5585](https://github.com/mapbox/mapbox-gl-native/pull/5585))
* The `text-pitch-alignment` property is now supported in stylesheets for improved street label legibility on a tilted map. ([#5288](https://github.com/mapbox/mapbox-gl-native/pull/5288))
* The `icon-text-fit` and `icon-text-fit-padding` properties are now supported in stylesheets, allowing the background of a shield to automatically resize to fit the shield’s text. ([#5334](https://github.com/mapbox/mapbox-gl-native/pull/5334))
* Improved the performance of relocating a point annotation by changing its `coordinate` property. ([#5385](https://github.com/mapbox/mapbox-gl-native/pull/5385))