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:35:14 -0700
commite421180129ba6899903b9ac9e1425ab3e9251fff (patch)
tree6dcece1656b61bb9db09a5fb7798e606825f67af
parent1d96191442cfd8cf798af8fad972e3bcc60f1677 (diff)
downloadqtlocation-mapboxgl-e421180129ba6899903b9ac9e1425ab3e9251fff.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. Cherry-picked from 1bc4f0e0273d6be24de56512fd52a147ea74f9e1.
-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.md2
5 files changed, 28 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 d74f99738a..f710378956 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
* Fixed an issue preventing MGLMapView from changing its viewport when a single annotation was passed into `-[MGLMapView showAnnotations:animated:]`. ([#5693](https://github.com/mapbox/mapbox-gl-native/pull/5693))
* If you subclass MGLAnnotationView, your implementation of `-setSelected:animated:` is now called with the correct value in the `animated` parameter, making it possible to animate a deselection. ([#5677](https://github.com/mapbox/mapbox-gl-native/pull/5677))
* The compass, Mapbox logo, and attribution button now accommodate the containing map view’s content insets. If your interface elements partially overlap the map view but do not affect the top and bottom layout guides, set the `automaticallyAdjustsScrollViewInsets` property to `NO` and set the `contentInset` property to a suitable value. ([#5671](https://github.com/mapbox/mapbox-gl-native/pull/5671))
+* 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))
## 3.3.0
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md
index a92e9f7656..db23be755d 100644
--- a/platform/macos/CHANGELOG.md
+++ b/platform/macos/CHANGELOG.md
@@ -1,7 +1,9 @@
# Changelog for Mapbox macOS SDK
## master
+
* Fixed an issue causing overlapping polylines and polygons to be drawn in undefined z-order. Shapes are always drawn in the order they are added to the map, from the oldest on the bottom to the newest on the top. ([#5710](https://github.com/mapbox/mapbox-gl-native/pull/5710))
+* 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))
* Replaced the wireframe debug mask with an overdraw visualization debug mask to match Mapbox GL JS’s overdraw inspector. ([#5403](https://github.com/mapbox/mapbox-gl-native/pull/5403))
* Improved the design of the generated API documentation. ([#5306](https://github.com/mapbox/mapbox-gl-native/pull/5306))