From 1bc4f0e0273d6be24de56512fd52a147ea74f9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Tue, 5 Jul 2016 17:37:55 -0700 Subject: [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. --- platform/darwin/src/MGLOfflineStorage.h | 8 ++++++++ platform/darwin/src/MGLOfflineStorage.mm | 13 +++++++++++++ platform/darwin/test/MGLOfflineStorageTests.m | 4 ++++ 3 files changed, 25 insertions(+) (limited to 'platform/darwin') 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 -- cgit v1.2.1