[ios, macos] Made offline database path public
Added getters for the path and URL of the offline database file and made use of the getter in places where the code had previously called -cacheURLIncludingSubdirectory: (which technically could’ve returned a different path each time it was called). Also reformatted some MGLOfflineStorage documentation comments.
This commit is contained in:
committed by
Minh Nguyễn
parent
ea308366d9
commit
ecfe9bdd98
@@ -721,7 +721,7 @@ NSArray<MGLAttributionInfo *> *MGLAttributionInfosFromAttributions(mbgl::MapSnap
|
||||
MGLRendererConfiguration *config = [MGLRendererConfiguration currentConfiguration];
|
||||
|
||||
mbgl::ResourceOptions resourceOptions;
|
||||
resourceOptions.withCachePath(MGLOfflineStorage.sharedOfflineStorage.mbglCachePath)
|
||||
resourceOptions.withCachePath(MGLOfflineStorage.sharedOfflineStorage.databasePath.UTF8String)
|
||||
.withAssetPath(NSBundle.mainBundle.resourceURL.path.UTF8String);
|
||||
|
||||
// Create the snapshotter
|
||||
|
||||
@@ -201,42 +201,6 @@ MGL_EXPORT
|
||||
*/
|
||||
@property (class, nonatomic, readonly) MGLOfflineStorage *sharedOfflineStorage;
|
||||
|
||||
#pragma mark - Adding Contents of File
|
||||
|
||||
/**
|
||||
Adds the offline packs located at the given file path to offline storage.
|
||||
|
||||
The file must be a valid offline region database bundled with the application
|
||||
or downloaded separately.
|
||||
|
||||
The resulting packs are added or updated to the shared offline storage object’s `packs`
|
||||
property, then the `completion` block is executed.
|
||||
|
||||
@param filePath A string representation of the file path. The file path must be
|
||||
writable as schema updates may be perfomed.
|
||||
@param completion The completion handler to call once the contents of the given
|
||||
file has been added to offline storage. This handler is executed asynchronously
|
||||
on the main queue.
|
||||
*/
|
||||
- (void)addContentsOfFile:(NSString *)filePath withCompletionHandler:(nullable MGLBatchedOfflinePackAdditionCompletionHandler)completion;
|
||||
|
||||
/**
|
||||
Adds the offline packs located at the given URL to offline storage.
|
||||
|
||||
The file must be a valid offline region database bundled with the application
|
||||
or downloaded separately.
|
||||
|
||||
The resulting packs are added or updated to the shared offline storage object’s `packs`
|
||||
property, then the `completion` block is executed.
|
||||
|
||||
@param fileURL A file URL specifying the file to add. URL should be a valid system path.
|
||||
The file URL must be writable as schema updates may be performed.
|
||||
@param completion The completion handler to call once the contents of the given
|
||||
file has been added to offline storage. This handler is executed asynchronously
|
||||
on the main queue.
|
||||
*/
|
||||
- (void)addContentsOfURL:(NSURL *)fileURL withCompletionHandler:(nullable MGLBatchedOfflinePackAdditionCompletionHandler)completion;
|
||||
|
||||
#pragma mark - Accessing the Delegate
|
||||
|
||||
/**
|
||||
@@ -249,6 +213,52 @@ MGL_EXPORT
|
||||
*/
|
||||
@property(nonatomic, weak, nullable) IBOutlet id<MGLOfflineStorageDelegate> delegate;
|
||||
|
||||
#pragma mark - Managing the Database of Offline Packs
|
||||
|
||||
/**
|
||||
The file path at which offline packs and the ambient cache are stored.
|
||||
*/
|
||||
@property (nonatomic, readonly, copy) NSString *databasePath;
|
||||
|
||||
/**
|
||||
The file URL at which offline packs and the ambient cache are stored.
|
||||
*/
|
||||
@property (nonatomic, readonly, copy) NSURL *databaseURL;
|
||||
|
||||
/**
|
||||
Adds the offline packs located at the given file path to offline storage.
|
||||
|
||||
The file must be a valid offline pack database bundled with the application or
|
||||
downloaded separately.
|
||||
|
||||
The resulting packs are added or updated to the shared offline storage object’s
|
||||
`packs` property, then the `completion` block is executed.
|
||||
|
||||
@param filePath A string representation of the file path. The file path must be
|
||||
writable as schema updates may be perfomed.
|
||||
@param completion The completion handler to call once the contents of the given
|
||||
file has been added to offline storage. This handler is executed
|
||||
asynchronously on the main queue.
|
||||
*/
|
||||
- (void)addContentsOfFile:(NSString *)filePath withCompletionHandler:(nullable MGLBatchedOfflinePackAdditionCompletionHandler)completion;
|
||||
|
||||
/**
|
||||
Adds the offline packs located at the given URL to offline storage.
|
||||
|
||||
The file must be a valid offline pack database bundled with the application or
|
||||
downloaded separately.
|
||||
|
||||
The resulting packs are added or updated to the shared offline storage object’s
|
||||
`packs` property, then the `completion` block is executed.
|
||||
|
||||
@param fileURL A file URL specifying the file to add. The URL should be a valid
|
||||
system path. The URL must be writable as schema updates may be performed.
|
||||
@param completion The completion handler to call once the contents of the given
|
||||
file has been added to offline storage. This handler is executed
|
||||
asynchronously on the main queue.
|
||||
*/
|
||||
- (void)addContentsOfURL:(NSURL *)fileURL withCompletionHandler:(nullable MGLBatchedOfflinePackAdditionCompletionHandler)completion;
|
||||
|
||||
#pragma mark - Managing Offline Packs
|
||||
|
||||
/**
|
||||
@@ -367,8 +377,7 @@ MGL_EXPORT
|
||||
*/
|
||||
@property (nonatomic, readonly) unsigned long long countOfBytesCompleted;
|
||||
|
||||
|
||||
#pragma mark - Managing Ambient Cache
|
||||
#pragma mark - Managing the Ambient Cache
|
||||
|
||||
/**
|
||||
Sets the maximum ambient cache size in bytes. The default maximum cache
|
||||
@@ -388,10 +397,9 @@ MGL_EXPORT
|
||||
specified amount.
|
||||
|
||||
@param cacheSize The maximum size in bytes for the ambient cache.
|
||||
@param completion The completion handler to call once the maximum ambient cache size
|
||||
has been set. This handler is executed synchronously on the main queue.
|
||||
@param completion The completion handler to call once the maximum ambient cache
|
||||
size has been set. This handler is executed synchronously on the main queue.
|
||||
*/
|
||||
|
||||
- (void)setMaximumAmbientCacheSize:(NSUInteger)cacheSize withCompletionHandler:(void (^)(NSError *_Nullable error))completion;
|
||||
|
||||
/**
|
||||
@@ -405,32 +413,29 @@ MGL_EXPORT
|
||||
Resources shared with offline packs will not be affected by this method.
|
||||
|
||||
@param completion The completion handler to call once the ambient cache has
|
||||
been revalidated. This handler is executed asynchronously on the main queue.
|
||||
been revalidated. This handler is executed asynchronously on the main queue.
|
||||
*/
|
||||
|
||||
- (void)invalidateAmbientCacheWithCompletionHandler:(void (^)(NSError *_Nullable error))completion;
|
||||
|
||||
/**
|
||||
Clears the ambient cache by deleting resources. This method does not
|
||||
affect resources shared with offline regions.
|
||||
Clears the ambient cache by deleting resources. This method does not affect
|
||||
resources shared with offline regions.
|
||||
|
||||
@param completion The completion handler to call once resources from
|
||||
the ambient cache have been cleared. This handler is executed
|
||||
asynchronously on the main queue.
|
||||
@param completion The completion handler to call once resources from the
|
||||
ambient cache have been cleared. This handler is executed asynchronously on
|
||||
the main queue.
|
||||
*/
|
||||
|
||||
- (void)clearAmbientCacheWithCompletionHandler:(void (^)(NSError *_Nullable error))completion;
|
||||
|
||||
/**
|
||||
Deletes the existing database, which includes both the ambient cache and offline packs,
|
||||
then reinitializes it.
|
||||
Deletes the existing database, which includes both the ambient cache and
|
||||
offline packs, then reinitializes it.
|
||||
|
||||
You typically do not need to call this method.
|
||||
|
||||
@param completion The completion handler to call once the pack has database has
|
||||
been reset. This handler is executed asynchronously on the main queue.
|
||||
*/
|
||||
|
||||
- (void)resetDatabaseWithCompletionHandler:(void (^)(NSError *_Nullable error))completion;
|
||||
|
||||
/**
|
||||
@@ -444,7 +449,8 @@ MGL_EXPORT
|
||||
in-progress requests, though subsequent requests should have access to the
|
||||
cached data.
|
||||
|
||||
To find out when the resource is ready to retrieve from the cache, use the -preloadData:forURL:modificationDate:expirationDate:eTag:mustRevalidate:completionHandler: method.
|
||||
To find out when the resource is ready to retrieve from the cache, use the `-preloadData:forURL:modificationDate:expirationDate:eTag:mustRevalidate:completionHandler:`
|
||||
method.
|
||||
|
||||
@param data Response data to store for this resource. The data is expected to
|
||||
be uncompressed; internally, the cache will compress data as necessary.
|
||||
@@ -460,25 +466,26 @@ MGL_EXPORT
|
||||
- (void)putResourceWithUrl:(NSURL *)url data:(NSData *)data modified:(nullable NSDate *)modified expires:(nullable NSDate *)expires etag:(nullable NSString *)etag mustRevalidate:(BOOL)mustRevalidate __attribute__((deprecated("", "-preloadData:forURL:modificationDate:expirationDate:eTag:mustRevalidate:")));
|
||||
|
||||
/**
|
||||
Inserts the provided resource into the ambient cache, calling a completion handler when finished.
|
||||
Inserts the provided resource into the ambient cache, calling a completion
|
||||
handler when finished.
|
||||
|
||||
This method is asynchronous. The data is available for in-progress requests as
|
||||
soon as the completion handler is called.
|
||||
This method is asynchronous. The data is available for in-progress requests as
|
||||
soon as the completion handler is called.
|
||||
|
||||
This method is asynchronous; the data may not be immediately available for
|
||||
in-progress requests, though subsequent requests should have access to the
|
||||
cached data.
|
||||
This method is asynchronous; the data may not be immediately available for
|
||||
in-progress requests, though subsequent requests should have access to the
|
||||
cached data.
|
||||
|
||||
@param data Response data to store for this resource. The data is expected to
|
||||
be uncompressed; internally, the cache will compress data as necessary.
|
||||
@param url The URL at which the data can normally be found.
|
||||
@param modified The date the resource was last modified.
|
||||
@param expires The date after which the resource is no longer valid.
|
||||
@param eTag An HTTP entity tag.
|
||||
@param mustRevalidate A Boolean value indicating whether the data is still
|
||||
usable past the expiration date.
|
||||
@param completion The completion handler to call once the data has been preloaded.
|
||||
This handler is executed asynchronously on the main queue.
|
||||
@param data Response data to store for this resource. The data is expected to
|
||||
be uncompressed; internally, the cache will compress data as necessary.
|
||||
@param url The URL at which the data can normally be found.
|
||||
@param modified The date the resource was last modified.
|
||||
@param expires The date after which the resource is no longer valid.
|
||||
@param eTag An HTTP entity tag.
|
||||
@param mustRevalidate A Boolean value indicating whether the data is still
|
||||
usable past the expiration date.
|
||||
@param completion The completion handler to call once the data has been
|
||||
preloaded. This handler is executed asynchronously on the main queue.
|
||||
*/
|
||||
- (void)preloadData:(NSData *)data forURL:(NSURL *)url modificationDate:(nullable NSDate *)modified expirationDate:(nullable NSDate *)expires eTag:(nullable NSString *)eTag mustRevalidate:(BOOL)mustRevalidate
|
||||
completionHandler:(nullable MGLOfflinePreloadDataCompletionHandler)completion;
|
||||
|
||||
@@ -49,7 +49,6 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
@property (nonatomic) std::shared_ptr<mbgl::DatabaseFileSource> mbglDatabaseFileSource;
|
||||
@property (nonatomic) std::shared_ptr<mbgl::FileSource> mbglOnlineFileSource;
|
||||
@property (nonatomic) std::shared_ptr<mbgl::FileSource> mbglFileSource;
|
||||
@property (nonatomic) std::string mbglCachePath;
|
||||
@property (nonatomic, getter=isPaused) BOOL paused;
|
||||
@end
|
||||
|
||||
@@ -153,6 +152,92 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
}
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
// Ensure network configuration & appropriate delegate prior to starting the
|
||||
// run loop. Calling `resetNativeNetworkManagerDelegate` is not necessary here,
|
||||
// since the shared manager already calls it.
|
||||
[MGLNetworkConfiguration sharedManager];
|
||||
|
||||
MGLInitializeRunLoop();
|
||||
|
||||
if (self = [super init]) {
|
||||
_databaseURL = [[self class] cacheURLIncludingSubdirectory:YES];
|
||||
NSString *cachePath = self.databasePath;
|
||||
NSAssert(cachePath, @"Offline pack database URL “%@” is not a valid file URL.", _databaseURL);
|
||||
|
||||
// Move the offline cache from v3.2.0-beta.1 to a location that can also
|
||||
// be used for ambient caching.
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:cachePath]) {
|
||||
NSString *legacyCachePath = [[self class] legacyCachePath];
|
||||
[[NSFileManager defaultManager] moveItemAtPath:legacyCachePath toPath:cachePath error:NULL];
|
||||
}
|
||||
|
||||
// Move the offline file cache from v3.2.x path to a subdirectory that
|
||||
// can be reliably excluded from backups.
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:cachePath]) {
|
||||
NSURL *subdirectorylessCacheURL = [[self class] cacheURLIncludingSubdirectory:NO];
|
||||
[[NSFileManager defaultManager] moveItemAtPath:subdirectorylessCacheURL.path toPath:cachePath error:NULL];
|
||||
}
|
||||
|
||||
mbgl::ResourceOptions options;
|
||||
options.withCachePath(cachePath.UTF8String)
|
||||
.withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String);
|
||||
_mbglFileSource = mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::ResourceLoader, options);
|
||||
_mbglOnlineFileSource = mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Network, options);
|
||||
_mbglDatabaseFileSource = std::static_pointer_cast<mbgl::DatabaseFileSource>(std::shared_ptr<mbgl::FileSource>(mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Database, options)));
|
||||
|
||||
// Observe for changes to the API base URL (and find out the current one).
|
||||
[[MGLAccountManager sharedManager] addObserver:self
|
||||
forKeyPath:@"apiBaseURL"
|
||||
options:(NSKeyValueObservingOptionInitial |
|
||||
NSKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
|
||||
// Observe for changes to the global access token (and find out the current one).
|
||||
[[MGLAccountManager sharedManager] addObserver:self
|
||||
forKeyPath:@"accessToken"
|
||||
options:(NSKeyValueObservingOptionInitial |
|
||||
NSKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[[MGLAccountManager sharedManager] removeObserver:self forKeyPath:@"apiBaseURL"];
|
||||
[[MGLAccountManager sharedManager] removeObserver:self forKeyPath:@"accessToken"];
|
||||
|
||||
for (MGLOfflinePack *pack in self.packs) {
|
||||
[pack invalidate];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *, id> *)change context:(void *)context {
|
||||
// Synchronize the file source’s access token with the global one in MGLAccountManager.
|
||||
if ([keyPath isEqualToString:@"accessToken"] && object == [MGLAccountManager sharedManager]) {
|
||||
NSString *accessToken = change[NSKeyValueChangeNewKey];
|
||||
if (![accessToken isKindOfClass:[NSNull class]]) {
|
||||
_mbglOnlineFileSource->setProperty(mbgl::ACCESS_TOKEN_KEY, accessToken.UTF8String);
|
||||
}
|
||||
} else if ([keyPath isEqualToString:@"apiBaseURL"] && object == [MGLAccountManager sharedManager]) {
|
||||
NSURL *apiBaseURL = change[NSKeyValueChangeNewKey];
|
||||
if ([apiBaseURL isKindOfClass:[NSNull class]]) {
|
||||
_mbglOnlineFileSource->setProperty(mbgl::API_BASE_URL_KEY, mbgl::util::API_BASE_URL);
|
||||
} else {
|
||||
_mbglOnlineFileSource->setProperty(mbgl::API_BASE_URL_KEY, apiBaseURL.absoluteString.UTF8String);
|
||||
}
|
||||
} else {
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Database management methods
|
||||
|
||||
- (NSString *)databasePath {
|
||||
return self.databaseURL.path;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the file URL to the offline cache, with the option to omit the private
|
||||
subdirectory for legacy (v3.2.0 - v3.2.3) migration purposes.
|
||||
@@ -219,88 +304,6 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
return legacyCachePath;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
// Ensure network configuration & appropriate delegate prior to starting the
|
||||
// run loop. Calling `resetNativeNetworkManagerDelegate` is not necessary here,
|
||||
// since the shared manager already calls it.
|
||||
[MGLNetworkConfiguration sharedManager];
|
||||
|
||||
MGLInitializeRunLoop();
|
||||
|
||||
if (self = [super init]) {
|
||||
NSURL *cacheURL = [[self class] cacheURLIncludingSubdirectory:YES];
|
||||
NSString *cachePath = cacheURL.path ?: @"";
|
||||
|
||||
// Move the offline cache from v3.2.0-beta.1 to a location that can also
|
||||
// be used for ambient caching.
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:cachePath]) {
|
||||
NSString *legacyCachePath = [[self class] legacyCachePath];
|
||||
[[NSFileManager defaultManager] moveItemAtPath:legacyCachePath toPath:cachePath error:NULL];
|
||||
}
|
||||
|
||||
// Move the offline file cache from v3.2.x path to a subdirectory that
|
||||
// can be reliably excluded from backups.
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:cachePath]) {
|
||||
NSURL *subdirectorylessCacheURL = [[self class] cacheURLIncludingSubdirectory:NO];
|
||||
[[NSFileManager defaultManager] moveItemAtPath:subdirectorylessCacheURL.path toPath:cachePath error:NULL];
|
||||
}
|
||||
|
||||
_mbglCachePath = cachePath.UTF8String;
|
||||
mbgl::ResourceOptions options;
|
||||
options.withCachePath(_mbglCachePath)
|
||||
.withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String);
|
||||
_mbglFileSource = mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::ResourceLoader, options);
|
||||
_mbglOnlineFileSource = mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Network, options);
|
||||
_mbglDatabaseFileSource = std::static_pointer_cast<mbgl::DatabaseFileSource>(std::shared_ptr<mbgl::FileSource>(mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Database, options)));
|
||||
|
||||
// Observe for changes to the API base URL (and find out the current one).
|
||||
[[MGLAccountManager sharedManager] addObserver:self
|
||||
forKeyPath:@"apiBaseURL"
|
||||
options:(NSKeyValueObservingOptionInitial |
|
||||
NSKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
|
||||
// Observe for changes to the global access token (and find out the current one).
|
||||
[[MGLAccountManager sharedManager] addObserver:self
|
||||
forKeyPath:@"accessToken"
|
||||
options:(NSKeyValueObservingOptionInitial |
|
||||
NSKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[[MGLAccountManager sharedManager] removeObserver:self forKeyPath:@"apiBaseURL"];
|
||||
[[MGLAccountManager sharedManager] removeObserver:self forKeyPath:@"accessToken"];
|
||||
|
||||
for (MGLOfflinePack *pack in self.packs) {
|
||||
[pack invalidate];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *, id> *)change context:(void *)context {
|
||||
// Synchronize the file source’s access token with the global one in MGLAccountManager.
|
||||
if ([keyPath isEqualToString:@"accessToken"] && object == [MGLAccountManager sharedManager]) {
|
||||
NSString *accessToken = change[NSKeyValueChangeNewKey];
|
||||
if (![accessToken isKindOfClass:[NSNull class]]) {
|
||||
_mbglOnlineFileSource->setProperty(mbgl::ACCESS_TOKEN_KEY, accessToken.UTF8String);
|
||||
}
|
||||
} else if ([keyPath isEqualToString:@"apiBaseURL"] && object == [MGLAccountManager sharedManager]) {
|
||||
NSURL *apiBaseURL = change[NSKeyValueChangeNewKey];
|
||||
if ([apiBaseURL isKindOfClass:[NSNull class]]) {
|
||||
_mbglOnlineFileSource->setProperty(mbgl::API_BASE_URL_KEY, mbgl::util::API_BASE_URL);
|
||||
} else {
|
||||
_mbglOnlineFileSource->setProperty(mbgl::API_BASE_URL_KEY, apiBaseURL.absoluteString.UTF8String);
|
||||
}
|
||||
} else {
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Offline merge methods
|
||||
|
||||
- (void)addContentsOfFile:(NSString *)filePath withCompletionHandler:(MGLBatchedOfflinePackAdditionCompletionHandler)completion {
|
||||
MGLLogDebug(@"Adding contentsOfFile: %@ completionHandler: %@", filePath, completion);
|
||||
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
|
||||
@@ -631,13 +634,7 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
#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];
|
||||
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.databasePath error:NULL];
|
||||
return attributes.fileSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*/
|
||||
@property (nonatomic) std::shared_ptr<mbgl::FileSource> mbglFileSource;
|
||||
|
||||
/**
|
||||
The shared offline cache path.
|
||||
*/
|
||||
@property (nonatomic) std::string mbglCachePath;
|
||||
|
||||
- (void)getPacksWithCompletionHandler:(void (^)(NSArray<MGLOfflinePack *> *packs, NSError * _Nullable error))completion;
|
||||
|
||||
@end
|
||||
|
||||
@@ -26,12 +26,13 @@
|
||||
NSString *bundleIdentifier = [NSBundle mgl_applicationBundleIdentifier];
|
||||
cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:bundleIdentifier];
|
||||
cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:@".mapbox"];
|
||||
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:cacheDirectoryURL.path], @"Cache subdirectory should exist.");
|
||||
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:cacheDirectoryURL.path], @"Directory containing database should exist.");
|
||||
|
||||
NSURL *cacheURL = [cacheDirectoryURL URLByAppendingPathComponent:@"cache.db"];
|
||||
XCTAssertEqualObjects(cacheURL, MGLOfflineStorage.sharedOfflineStorage.databaseURL);
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtURL:cacheURL error:nil];
|
||||
XCTAssertFalse([[NSFileManager defaultManager] fileExistsAtPath:cacheURL.path], @"Cache subdirectory should not exist.");
|
||||
XCTAssertFalse([[NSFileManager defaultManager] fileExistsAtPath:cacheURL.path], @"Database should not exist.");
|
||||
}
|
||||
|
||||
- (void)setUp {
|
||||
|
||||
@@ -15,12 +15,16 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
|
||||
* Fixed a crash when calling the `-[MGLStyle removeImageForName:]` method with the name of a nonexistent image. ([mapbox/mapbox-gl-native#16391](https://github.com/mapbox/mapbox-gl-native/pull/16391))
|
||||
* Fixed an issue where properties such as `MGLFillStyleLayer.fillColor` and `MGLLineStyleLayer.lineColor` misinterpreted non-opaque `UIColor`s. ([#266](https://github.com/mapbox/mapbox-gl-native-ios/pull/266))
|
||||
|
||||
### Other changes
|
||||
### Offline maps
|
||||
|
||||
* Added the `-[MGLOfflinePack setContext:completionHandler:]` method for replacing the data associated with an offline pack, such as a name. ([#288](https://github.com/mapbox/mapbox-gl-native-ios/pull/288))
|
||||
* Added the `MGLOfflineStorage.databasePath` and `MGLOfflineStorage.databaseURL` properties. ([#298](https://github.com/mapbox/mapbox-gl-native-ios/pull/298))
|
||||
* Fixed an error that occurred if your implementation of the `-[MGLOfflineStorageDelegate offlineStorage:URLForResourceOfKind:]` method returned a local file URL. ([mapbox/mapbox-gl-native#16428](https://github.com/mapbox/mapbox-gl-native/pull/16428))
|
||||
|
||||
### Other changes
|
||||
|
||||
* Fixed a crash when encountering an invalid polyline. ([mapbox/mapbox-gl-native#16409](https://github.com/mapbox/mapbox-gl-native/pull/16409))
|
||||
* Fixed an issue where an `MGLMapSnapshotOptions` with an invalid `MGLMapCamera.centerCoordinate`, negative `MGLMapCamera.heading`, negative `MGLMapCamera.pitch`, and negative `MGLMapSnapshotOptions.zoomLevel` resulted in a snapshot centered on Null Island at zoom level 0 even if the style specified a different initial center coordinate or zoom level. ([#280](https://github.com/mapbox/mapbox-gl-native-ios/pull/280))
|
||||
* Fixed an error that occurred if your implementation of the `-[MGLOfflineStorageDelegate offlineStorage:URLForResourceOfKind:]` method returned a local file URL. ([mapbox/mapbox-gl-native#16428](https://github.com/mapbox/mapbox-gl-native/pull/16428))
|
||||
* Certain logging statements no longer run on the main thread. ([mapbox/mapbox-gl-native#16325](https://github.com/mapbox/mapbox-gl-native/pull/16325))
|
||||
* Fixed an issue that prevented the Maps SDK from warning about a misconfiguration that violated the Mapbox ToS. ([#288](https://github.com/mapbox/mapbox-gl-native-ios/pull/288))
|
||||
|
||||
|
||||
@@ -494,7 +494,7 @@ public:
|
||||
.withCrossSourceCollisions(enableCrossSourceCollisions);
|
||||
|
||||
mbgl::ResourceOptions resourceOptions;
|
||||
resourceOptions.withCachePath([[MGLOfflineStorage sharedOfflineStorage] mbglCachePath])
|
||||
resourceOptions.withCachePath(MGLOfflineStorage.sharedOfflineStorage.databasePath.UTF8String)
|
||||
.withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String);
|
||||
|
||||
NSAssert(!_mbglMap, @"_mbglMap should be NULL");
|
||||
|
||||
@@ -13,12 +13,16 @@
|
||||
* Fixed a crash when calling the `-[MGLStyle removeImageForName:]` method with the name of a nonexistent image. ([mapbox/mapbox-gl-native#16391](https://github.com/mapbox/mapbox-gl-native/pull/16391))
|
||||
* Fixed an issue where properties such as `MGLFillStyleLayer.fillColor` and `MGLLineStyleLayer.lineColor` misinterpreted non-opaque `NSColor`s. ([#266](https://github.com/mapbox/mapbox-gl-native-ios/pull/266))
|
||||
|
||||
### Other changes
|
||||
### Offline maps
|
||||
|
||||
* Added the `-[MGLOfflinePack setContext:completionHandler:]` method for replacing the data associated with an offline pack, such as a name. ([#288](https://github.com/mapbox/mapbox-gl-native-ios/pull/288))
|
||||
* Added the `MGLOfflineStorage.databasePath` and `MGLOfflineStorage.databaseURL` properties. ([#298](https://github.com/mapbox/mapbox-gl-native-ios/pull/298))
|
||||
* Fixed an error that occurred if your implementation of the `-[MGLOfflineStorageDelegate offlineStorage:URLForResourceOfKind:]` method returned a local file URL. ([mapbox/mapbox-gl-native#16428](https://github.com/mapbox/mapbox-gl-native/pull/16428))
|
||||
|
||||
### Other changes
|
||||
|
||||
* Fixed a crash when encountering an invalid polyline. ([mapbox/mapbox-gl-native#16409](https://github.com/mapbox/mapbox-gl-native/pull/16409))
|
||||
* Fixed an issue where an `MGLMapSnapshotOptions` with an invalid `MGLMapCamera.centerCoordinate`, negative `MGLMapCamera.heading`, negative `MGLMapCamera.pitch`, and negative `MGLMapSnapshotOptions.zoomLevel` resulted in a snapshot centered on Null Island at zoom level 0 even if the style specified a different initial center coordinate or zoom level. ([#280](https://github.com/mapbox/mapbox-gl-native-ios/pull/280))
|
||||
* Fixed an error that occurred if your implementation of the `-[MGLOfflineStorageDelegate offlineStorage:URLForResourceOfKind:]` method returned a local file URL. ([mapbox/mapbox-gl-native#16428](https://github.com/mapbox/mapbox-gl-native/pull/16428))
|
||||
* Certain logging statements no longer run on the main thread. ([mapbox/mapbox-gl-native#16325](https://github.com/mapbox/mapbox-gl-native/pull/16325))
|
||||
|
||||
## 0.15.1
|
||||
|
||||
@@ -293,7 +293,7 @@ public:
|
||||
.withCrossSourceCollisions(enableCrossSourceCollisions);
|
||||
|
||||
mbgl::ResourceOptions resourceOptions;
|
||||
resourceOptions.withCachePath([[MGLOfflineStorage sharedOfflineStorage] mbglCachePath])
|
||||
resourceOptions.withCachePath(MGLOfflineStorage.sharedOfflineStorage.databasePath.UTF8String)
|
||||
.withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String);
|
||||
|
||||
_mbglMap = std::make_unique<mbgl::Map>(*_rendererFrontend, *_mbglView, mapOptions, resourceOptions);
|
||||
|
||||
Reference in New Issue
Block a user