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

Commit

Permalink
Add a flag to enforce using catched tiles (#416)
Browse files Browse the repository at this point in the history
* Add a flag to enforce using catched tiles

* Update changelog
  • Loading branch information
fabian-guerra authored Sep 3, 2020
1 parent 1458061 commit 14c4d1b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
11 changes: 11 additions & 0 deletions platform/darwin/src/MGLNetworkConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ MGL_EXPORT
*/
@property (atomic, strong, null_resettable) NSURLSessionConfiguration *sessionConfiguration;

/**
A Boolean value indicating whether the current `NSURLSessionConfiguration` stops
making network requests.
When this property is set to `NO` `MGLMapView` will rely solely on pre-cached
tiles.
The default value of this property is `YES`.
*/
@property (atomic, assign) BOOL connected;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#import "MGLAccountManager_Private.h"
#endif

#include <mbgl/storage/network_status.hpp>

#import "MGLReachability.h"

static NSString * const MGLStartTime = @"start_time";
Expand Down Expand Up @@ -64,6 +66,19 @@ + (NSURLSessionConfiguration *)defaultSessionConfiguration {
return sessionConfiguration;
}

- (void)setConnected:(BOOL)connected {
if (!connected) {
mbgl::NetworkStatus::Set(mbgl::NetworkStatus::Status::Offline);
} else {
mbgl::NetworkStatus::Set(mbgl::NetworkStatus::Status::Online);
}
}

- (BOOL)connected {
auto status = mbgl::NetworkStatus::Get();
return status == mbgl::NetworkStatus::Status::Online;
}

#pragma mark - MGLNativeNetworkDelegate

- (NSURLSession *)sessionForNetworkManager:(MGLNativeNetworkManager *)networkManager {
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Added an approximate user location halo when `MGLLocationManager.accuracyAuthorization` is set to `CLAccuracyAuthorizationReducedAccuracy`. ([#381](https://github.com/mapbox/mapbox-gl-native-ios/pull/381))
* The `MGLAccuracyAuthorizationDescription` as element of `NSLocationTemporaryUsageDescriptionDictionary` Info.plist key can now be set to describe why you request accuracy authorization. ([#392](https://github.com/mapbox/mapbox-gl-native-ios/pull/392))
* Added `[MGLMapViewDelegate mapViewStyleForDefaultUserLocationAnnotationView:]` and `MGLUserLocationAnnotationViewStyle` class to allow developers customize the default user location annotation view UI style. ([#403](https://github.com/mapbox/mapbox-gl-native-ios/pull/403))
* Added `MGLNetworkConfiguration.connected` property to enforce `MGLMapView` to use catched tiles. ([#416](https://github.com/mapbox/mapbox-gl-native-ios/pull/416))

## 6.1.0 - August 26, 2020

Expand Down
12 changes: 6 additions & 6 deletions platform/ios/ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@
DAF2571B201901E200367EF5 /* MGLHillshadeStyleLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = DAF25718201901E200367EF5 /* MGLHillshadeStyleLayer.h */; settings = {ATTRIBUTES = (Public, ); }; };
DAF2571C201901E200367EF5 /* MGLHillshadeStyleLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = DAF25718201901E200367EF5 /* MGLHillshadeStyleLayer.h */; settings = {ATTRIBUTES = (Public, ); }; };
DAF25720201902BC00367EF5 /* MGLHillshadeStyleLayerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DAF2571F201902BB00367EF5 /* MGLHillshadeStyleLayerTests.mm */; };
DD0902A91DB1929D00C5BDCE /* MGLNetworkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0902A21DB18DE700C5BDCE /* MGLNetworkConfiguration.m */; };
DD0902AA1DB1929D00C5BDCE /* MGLNetworkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0902A21DB18DE700C5BDCE /* MGLNetworkConfiguration.m */; };
DD0902A91DB1929D00C5BDCE /* MGLNetworkConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD0902A21DB18DE700C5BDCE /* MGLNetworkConfiguration.mm */; };
DD0902AA1DB1929D00C5BDCE /* MGLNetworkConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD0902A21DB18DE700C5BDCE /* MGLNetworkConfiguration.mm */; };
DD0902AB1DB192A800C5BDCE /* MGLNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = DD0902A41DB18F1B00C5BDCE /* MGLNetworkConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; };
DD4823751D94AE6C00EB71B7 /* fill_filter_style.json in Resources */ = {isa = PBXBuildFile; fileRef = DD4823721D94AE6C00EB71B7 /* fill_filter_style.json */; };
DD4823761D94AE6C00EB71B7 /* line_filter_style.json in Resources */ = {isa = PBXBuildFile; fileRef = DD4823731D94AE6C00EB71B7 /* line_filter_style.json */; };
Expand Down Expand Up @@ -1355,7 +1355,7 @@
DAFEB3762093AE6800A86A83 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ko; path = ko.lproj/Foundation.stringsdict; sourceTree = "<group>"; };
DAFEB3772093AE7900A86A83 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
DAFEB3782093AE9200A86A83 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ko; path = ko.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
DD0902A21DB18DE700C5BDCE /* MGLNetworkConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLNetworkConfiguration.m; sourceTree = "<group>"; };
DD0902A21DB18DE700C5BDCE /* MGLNetworkConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLNetworkConfiguration.mm; sourceTree = "<group>"; };
DD0902A41DB18F1B00C5BDCE /* MGLNetworkConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLNetworkConfiguration.h; sourceTree = "<group>"; };
DD4823721D94AE6C00EB71B7 /* fill_filter_style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = fill_filter_style.json; sourceTree = "<group>"; };
DD4823731D94AE6C00EB71B7 /* line_filter_style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = line_filter_style.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2028,7 +2028,7 @@
927FBCFE1F4DB05500F8BF1F /* MGLMapSnapshotter.mm */,
DD0902A41DB18F1B00C5BDCE /* MGLNetworkConfiguration.h */,
1F2B94BF221636D800210640 /* MGLNetworkConfiguration_Private.h */,
DD0902A21DB18DE700C5BDCE /* MGLNetworkConfiguration.m */,
DD0902A21DB18DE700C5BDCE /* MGLNetworkConfiguration.mm */,
DA35D9BF240916290013ECB0 /* MGLReachability.h */,
DA35D9BE240916290013ECB0 /* MGLReachability.m */,
3EA9337830C7738BF7F5493C /* MGLRendererConfiguration.h */,
Expand Down Expand Up @@ -3262,7 +3262,7 @@
DA8848501CBAFB9800AB86E3 /* MGLAnnotationImage.m in Sources */,
DA8848281CBAFA6200AB86E3 /* MGLShape.mm in Sources */,
DA35A2B31CCA141D00E826B2 /* MGLCompassDirectionFormatter.m in Sources */,
DD0902A91DB1929D00C5BDCE /* MGLNetworkConfiguration.m in Sources */,
DD0902A91DB1929D00C5BDCE /* MGLNetworkConfiguration.mm in Sources */,
35D13AB91D3D15E300AFB4E0 /* MGLStyleLayer.mm in Sources */,
74CB5EB3219B252C00102936 /* MGLStyleLayerManager.mm in Sources */,
DA35A2CB1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */,
Expand Down Expand Up @@ -3361,7 +3361,7 @@
9C6E282C22A981580056B7BE /* MGLMapboxEvents.m in Sources */,
DAA4E41F1CBB730400178DFB /* MGLMultiPoint.mm in Sources */,
96E6145C22CC169000109F14 /* MGLCompassButton.mm in Sources */,
DD0902AA1DB1929D00C5BDCE /* MGLNetworkConfiguration.m in Sources */,
DD0902AA1DB1929D00C5BDCE /* MGLNetworkConfiguration.mm in Sources */,
DA35A2B41CCA141D00E826B2 /* MGLCompassDirectionFormatter.m in Sources */,
35D13ABA1D3D15E300AFB4E0 /* MGLStyleLayer.mm in Sources */,
071BBAFF1EE7613E001FB02A /* MGLImageSource.mm in Sources */,
Expand Down
10 changes: 10 additions & 0 deletions platform/ios/test/MGLNetworkConfigurationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ - (void)testAccessingEventsFromMultipleThreads {

[self waitForExpectations:@[expectation] timeout:10.0];
}

- (void)testConnected {
MGLNetworkConfiguration *manager = [MGLNetworkConfiguration sharedManager];

XCTAssertTrue(manager.connected);
manager.connected = NO;
XCTAssertFalse(manager.connected);
manager.connected = YES;
XCTAssertTrue(manager.connected);
}
@end

0 comments on commit 14c4d1b

Please sign in to comment.