Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Post offline pack notifications from MGLOfflinePack #7952

Merged
merged 2 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions platform/darwin/src/MGLOfflinePack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#import "MGLOfflineRegion_Private.h"
#import "MGLTilePyramidOfflineRegion.h"

#import "NSValue+MGLAdditions.h"

#include <mbgl/storage/default_file_source.hpp>

/**
Expand Down Expand Up @@ -37,7 +39,6 @@

@interface MGLOfflinePack ()

@property (nonatomic, weak, nullable) id <MGLOfflinePackDelegate> delegate;
@property (nonatomic, nullable, readwrite) mbgl::OfflineRegion *mbglOfflineRegion;
@property (nonatomic, readwrite) MGLOfflinePackProgress progress;

Expand Down Expand Up @@ -175,7 +176,29 @@ - (void)offlineRegionStatusDidChange:(mbgl::OfflineRegionStatus)status {
progress.maximumResourcesExpected = status.requiredResourceCountIsPrecise ? status.requiredResourceCount : UINT64_MAX;
self.progress = progress;

[self.delegate offlinePack:self progressDidChange:progress];
NSDictionary *userInfo = @{MGLOfflinePackUserInfoKeyState: @(self.state),
MGLOfflinePackUserInfoKeyProgress: [NSValue valueWithMGLOfflinePackProgress:progress]};

NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
[noteCenter postNotificationName:MGLOfflinePackProgressChangedNotification
object:self
userInfo:userInfo];
}

- (void)didReceiveError:(NSError *)error {
NSDictionary *userInfo = @{ MGLOfflinePackUserInfoKeyError: error };
NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
[noteCenter postNotificationName:MGLOfflinePackErrorNotification
object:self
userInfo:userInfo];
}

- (void)didReceiveMaximumAllowedMapboxTiles:(uint64_t)limit {
NSDictionary *userInfo = @{ MGLOfflinePackUserInfoKeyMaximumCount: @(limit) };
NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
[noteCenter postNotificationName:MGLOfflinePackMaximumMapboxTilesReachedNotification
object:self
userInfo:userInfo];
}

NSError *MGLErrorFromResponseError(mbgl::Response::Error error) {
Expand Down Expand Up @@ -211,12 +234,12 @@ - (void)offlineRegionStatusDidChange:(mbgl::OfflineRegionStatus)status {

void MBGLOfflineRegionObserver::responseError(mbgl::Response::Error error) {
dispatch_async(dispatch_get_main_queue(), ^{
[pack.delegate offlinePack:pack didReceiveError:MGLErrorFromResponseError(error)];
[pack didReceiveError:MGLErrorFromResponseError(error)];
});
}

void MBGLOfflineRegionObserver::mapboxTileCountLimitExceeded(uint64_t limit) {
dispatch_async(dispatch_get_main_queue(), ^{
[pack.delegate offlinePack:pack didReceiveMaximumAllowedMapboxTiles:limit];
[pack didReceiveMaximumAllowedMapboxTiles:limit];
});
}
54 changes: 0 additions & 54 deletions platform/darwin/src/MGLOfflinePack_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@

NS_ASSUME_NONNULL_BEGIN

@protocol MGLOfflinePackDelegate;

@interface MGLOfflinePack (Private)

/**
The pack’s delegate.

You can use the offline pack delegate to be notified of any changes in the
pack’s progress and of any errors while downloading. For more information, see
the `MGLOfflinePackDelegate` documentation.
*/
@property (nonatomic, weak, nullable) id <MGLOfflinePackDelegate> delegate;

@property (nonatomic, nullable) mbgl::OfflineRegion *mbglOfflineRegion;

@property (nonatomic, readwrite) MGLOfflinePackState state;
Expand All @@ -31,47 +20,4 @@ NS_ASSUME_NONNULL_BEGIN

@end

/**
The `MGLOfflinePackDelegate` protocol defines methods that a delegate of an
`MGLOfflinePack` object can optionally implement to be notified of any changes
in the pack’s download progress and of any errors while downloading.
*/
@protocol MGLOfflinePackDelegate <NSObject>

/**
Sent whenever the pack’s state or download progress changes. Every change to a
field in the `progress` property corresponds to an invocation of this method.

@param pack The pack whose state of progress changed.
@param progress The updated progress. To get the updated state, refer to the
`state` property.
*/
- (void)offlinePack:(MGLOfflinePack *)pack progressDidChange:(MGLOfflinePackProgress)progress;

/**
Sent whenever the pack encounters an error while downloading.

Download errors may be recoverable. For example, this pack’s implementation may
attempt to re-request failed resources based on an exponential backoff
strategy or upon the restoration of network access.

@param pack The pack that encountered an error.
@param error A download error. For a list of possible error codes, see
`MGLErrorCode`.
*/
- (void)offlinePack:(MGLOfflinePack *)pack didReceiveError:(NSError *)error;

/**
Sent when the maximum number of Mapbox-hosted tiles has been downloaded and
stored on the current device.

Once this limit is reached, no instance of `MGLOfflinePack` can download
additional tiles from Mapbox APIs until already downloaded tiles are removed by
calling the `-[MGLOfflineStorage removePack:withCompletionHandler:]` method.
Contact your Mapbox sales representative to have the limit raised.
*/
- (void)offlinePack:(MGLOfflinePack *)pack didReceiveMaximumAllowedMapboxTiles:(uint64_t)maximumCount;

@end

NS_ASSUME_NONNULL_END
28 changes: 1 addition & 27 deletions platform/darwin/src/MGLOfflineStorage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
const MGLOfflinePackUserInfoKey MGLOfflinePackUserInfoKeyMaximumCount = @"MaximumCount";
NSString * const MGLOfflinePackMaximumCountUserInfoKey = MGLOfflinePackUserInfoKeyMaximumCount;

@interface MGLOfflineStorage () <MGLOfflinePackDelegate>
@interface MGLOfflineStorage ()

@property (nonatomic, strong, readwrite) NS_MUTABLE_ARRAY_OF(MGLOfflinePack *) *packs;
@property (nonatomic) mbgl::DefaultFileSource *mbglFileSource;
Expand Down Expand Up @@ -197,7 +197,6 @@ - (void)addPackForRegion:(id <MGLOfflineRegion>)region withContext:(NSData *)con
pack.state = MGLOfflinePackStateInactive;
MGLOfflineStorage *strongSelf = weakSelf;
[[strongSelf mutableArrayValueForKey:@"packs"] addObject:pack];
pack.delegate = strongSelf;
if (completion) {
completion(pack, error);
}
Expand Down Expand Up @@ -269,10 +268,6 @@ - (void)reloadPacks {
[pack invalidate];
}
self.packs = [packs mutableCopy];

for (MGLOfflinePack *pack in packs) {
pack.delegate = self;
}
}];
}

Expand Down Expand Up @@ -317,25 +312,4 @@ - (unsigned long long)countOfBytesCompleted {
return attributes.fileSize;
}

#pragma mark MGLOfflinePackDelegate methods

- (void)offlinePack:(MGLOfflinePack *)pack progressDidChange:(__unused MGLOfflinePackProgress)progress {
[[NSNotificationCenter defaultCenter] postNotificationName:MGLOfflinePackProgressChangedNotification object:pack userInfo:@{
MGLOfflinePackUserInfoKeyState: @(pack.state),
MGLOfflinePackUserInfoKeyProgress: [NSValue valueWithMGLOfflinePackProgress:progress],
}];
}

- (void)offlinePack:(MGLOfflinePack *)pack didReceiveError:(NSError *)error {
[[NSNotificationCenter defaultCenter] postNotificationName:MGLOfflinePackErrorNotification object:pack userInfo:@{
MGLOfflinePackUserInfoKeyError: error,
}];
}

- (void)offlinePack:(MGLOfflinePack *)pack didReceiveMaximumAllowedMapboxTiles:(uint64_t)maximumCount {
[[NSNotificationCenter defaultCenter] postNotificationName:MGLOfflinePackMaximumMapboxTilesReachedNotification object:pack userInfo:@{
MGLOfflinePackUserInfoKeyMaximumCount: @(maximumCount),
}];
}

@end
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT

### Other changes

* `MGLOfflinePack` and `MGLOfflineStorage` now conform to standard notification posting patterns. Notifications are posted by `MGLOfflinePack` instances. `userInfo` dictionary still contains values with pack's `state` and `progress` properties for backwards compatibility. ([#7952](https://github.com/mapbox/mapbox-gl-native/pull/7952))
* Fixed an issue where translucent, non-view-backed point annotations along tile boundaries would be drawn darker than expected. ([#6832](https://github.com/mapbox/mapbox-gl-native/pull/6832))
* Fixed flickering that occurred when panning past the antimeridian. ([#7574](https://github.com/mapbox/mapbox-gl-native/pull/7574))
* Fixed an issue that could prevent a cached style from appearing while the device is offline. ([#7770](https://github.com/mapbox/mapbox-gl-native/pull/7770))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0820"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
1 change: 1 addition & 0 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

### Other changes

* `MGLOfflinePack` and `MGLOfflineStorage` now conform to standard notification posting patterns. Notifications are posted by `MGLOfflinePack` instances. `userInfo` dictionary still contains values with pack's `state` and `progress` properties for backwards compatibility. ([#7952](https://github.com/mapbox/mapbox-gl-native/pull/7952))
* Fixed an issue where translucent point annotations along tile boundaries would be drawn darker than expected. ([#6832](https://github.com/mapbox/mapbox-gl-native/pull/6832))
* Fixed flickering that occurred when panning past the antimeridian. ([#7574](https://github.com/mapbox/mapbox-gl-native/pull/7574))
* Fixed an issue that could prevent a cached style from appearing while the computer is offline. ([#7770](https://github.com/mapbox/mapbox-gl-native/pull/7770))
Expand Down