[ios, macos] Expose the url session configuration object. (#13886)
The `MGLNetworkConfiguration` class was make public, and added `sessionConfiguration` property to let developers customize the `NSURLSessionConfiguration` object that is used to make HTTP requests in the SDK.
This commit is contained in:
committed by
GitHub
parent
1c99b199c6
commit
1fc7a9b82e
@@ -2,6 +2,7 @@
|
||||
"//": "This file can be edited manually and is the canonical source.",
|
||||
"sources": [
|
||||
"platform/darwin/src/MGLLoggingConfiguration.m",
|
||||
"platform/darwin/src/MGLNetworkConfiguration.m",
|
||||
"platform/darwin/src/http_file_source.mm",
|
||||
"platform/default/src/mbgl/storage/sqlite3.cpp"
|
||||
],
|
||||
|
||||
@@ -1,18 +1,37 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "MGLFoundation.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
The MGLNetworkConfiguration object provides a global way to set a base API URL for
|
||||
retrieval of map data, styles, and other resources.
|
||||
|
||||
Currently, MGLNetworkConfiguration is a private API.
|
||||
The `MGLNetworkConfiguration` object provides a global way to set a base
|
||||
`NSURLSessionConfiguration`, and other resources.
|
||||
*/
|
||||
MGL_EXPORT
|
||||
@interface MGLNetworkConfiguration : NSObject
|
||||
|
||||
/// Returns the shared instance of the `MGLNetworkConfiguration` class.
|
||||
/**
|
||||
Returns the shared instance of the `MGLNetworkConfiguration` class.
|
||||
*/
|
||||
@property (class, nonatomic, readonly) MGLNetworkConfiguration *sharedManager;
|
||||
|
||||
/**
|
||||
The session configuration object that is used by the `NSURLSession` objects
|
||||
in this SDK.
|
||||
|
||||
If this property is set to nil or if no session configuration is provided this property
|
||||
is set to the default session configuration.
|
||||
|
||||
Assign this object before instantiating any `MGLMapView` object.
|
||||
|
||||
@note: `NSURLSession` objects store a copy of this configuration. Any further changes
|
||||
to mutable properties on this configuration object passed to a session’s initializer
|
||||
will not affect the behavior of that session.
|
||||
|
||||
*/
|
||||
@property (atomic, strong, null_resettable) NSURLSessionConfiguration *sessionConfiguration;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -1,23 +1,51 @@
|
||||
#import "MGLNetworkConfiguration.h"
|
||||
|
||||
@interface MGLNetworkConfiguration ()
|
||||
|
||||
@property (strong) NSURLSessionConfiguration *sessionConfig;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MGLNetworkConfiguration
|
||||
|
||||
+ (instancetype)sharedManager {
|
||||
static dispatch_once_t onceToken;
|
||||
static MGLNetworkConfiguration *_sharedManager;
|
||||
void (^setupBlock)(void) = ^{
|
||||
dispatch_once(&onceToken, ^{
|
||||
_sharedManager = [[self alloc] init];
|
||||
});
|
||||
};
|
||||
if (![[NSThread currentThread] isMainThread]) {
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
setupBlock();
|
||||
});
|
||||
} else {
|
||||
setupBlock();
|
||||
}
|
||||
dispatch_once(&onceToken, ^{
|
||||
_sharedManager = [[self alloc] init];
|
||||
_sharedManager.sessionConfiguration = nil;
|
||||
});
|
||||
|
||||
return _sharedManager;
|
||||
}
|
||||
|
||||
- (void)setSessionConfiguration:(NSURLSessionConfiguration *)sessionConfiguration {
|
||||
@synchronized (self) {
|
||||
if (sessionConfiguration == nil) {
|
||||
_sessionConfig = [self defaultSessionConfiguration];
|
||||
} else {
|
||||
_sessionConfig = sessionConfiguration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSURLSessionConfiguration *)sessionConfiguration {
|
||||
NSURLSessionConfiguration *sessionConfig = nil;
|
||||
@synchronized (self) {
|
||||
sessionConfig = _sessionConfig;
|
||||
}
|
||||
return sessionConfig;
|
||||
}
|
||||
|
||||
- (NSURLSessionConfiguration *)defaultSessionConfiguration {
|
||||
NSURLSessionConfiguration* sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||
|
||||
sessionConfiguration.timeoutIntervalForResource = 30;
|
||||
sessionConfiguration.HTTPMaximumConnectionsPerHost = 8;
|
||||
sessionConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
|
||||
sessionConfiguration.URLCache = nil;
|
||||
|
||||
return sessionConfiguration;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MGLLoggingConfiguration_Private.h"
|
||||
#import "MGLNetworkConfiguration.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
@@ -82,13 +83,10 @@ class HTTPFileSource::Impl {
|
||||
public:
|
||||
Impl() {
|
||||
@autoreleasepool {
|
||||
NSURLSessionConfiguration* sessionConfig =
|
||||
[NSURLSessionConfiguration defaultSessionConfiguration];
|
||||
sessionConfig.timeoutIntervalForResource = 30;
|
||||
sessionConfig.HTTPMaximumConnectionsPerHost = 8;
|
||||
sessionConfig.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
|
||||
sessionConfig.URLCache = nil;
|
||||
|
||||
NSURLSessionConfiguration *sessionConfig =
|
||||
[MGLNetworkConfiguration sharedManager].sessionConfiguration;
|
||||
|
||||
session = [NSURLSession sessionWithConfiguration:sessionConfig];
|
||||
|
||||
userAgent = getUserAgent();
|
||||
|
||||
@@ -7,6 +7,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
|
||||
* Fixed a bug where setting `MGLMapView.userTrackingMode` to `MGLUserTrackingModeFollowWithHeading` or `MGLUserTrackingModeFollowWithCourse` would be ignored if the user’s location was not already available. ([#13849](https://github.com/mapbox/mapbox-gl-native/pull/13849))
|
||||
* Improved tilt gesture performance. ([#13902](https://github.com/mapbox/mapbox-gl-native/pull/13902))
|
||||
* Fixed a bug where `layoutSubviews` was always called on device rotation, regardless of the application's or top-most view controller's supported orientations. ([#13900](https://github.com/mapbox/mapbox-gl-native/pull/13900))
|
||||
* Added `MGLNetworkConfiguration` class to customize the SDK's `NSURLSessionConfiguration` object. ([#11447](https://github.com/mapbox/mapbox-gl-native/pull/13886))
|
||||
|
||||
## 4.8.0 - January 30, 2019
|
||||
|
||||
|
||||
@@ -443,7 +443,7 @@
|
||||
96E516F22000596D00A02306 /* NSException+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8848141CBAFA6200AB86E3 /* NSException+MGLAdditions.h */; };
|
||||
96E516F32000597100A02306 /* NSDictionary+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 408AA8551DAEDA0800022900 /* NSDictionary+MGLAdditions.h */; };
|
||||
96E516F42000597D00A02306 /* NSData+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 35305D461D22AA450007D005 /* NSData+MGLAdditions.h */; };
|
||||
96E516F5200059B100A02306 /* MGLNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = DD0902A41DB18F1B00C5BDCE /* MGLNetworkConfiguration.h */; };
|
||||
96E516F5200059B100A02306 /* MGLNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = DD0902A41DB18F1B00C5BDCE /* MGLNetworkConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
96E516F6200059EC00A02306 /* MGLRendererFrontend.h in Headers */ = {isa = PBXBuildFile; fileRef = 92F2C3EC1F0E3C3A00268EC0 /* MGLRendererFrontend.h */; };
|
||||
96E516F720005A2700A02306 /* MGLAnnotationContainerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 40EDA1BD1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.h */; };
|
||||
96E516F820005A3000A02306 /* MGLCompactCalloutView.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8848441CBAFB9800AB86E3 /* MGLCompactCalloutView.h */; };
|
||||
@@ -722,7 +722,7 @@
|
||||
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 */; };
|
||||
DD0902AB1DB192A800C5BDCE /* MGLNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = DD0902A41DB18F1B00C5BDCE /* MGLNetworkConfiguration.h */; };
|
||||
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 */; };
|
||||
DD4823771D94AE6C00EB71B7 /* numeric_filter_style.json in Resources */ = {isa = PBXBuildFile; fileRef = DD4823741D94AE6C00EB71B7 /* numeric_filter_style.json */; };
|
||||
|
||||
@@ -158,6 +158,7 @@
|
||||
"MGLAccountManager.h": "platform/darwin/src/MGLAccountManager.h",
|
||||
"NSValue+MGLAdditions.h": "platform/darwin/src/NSValue+MGLAdditions.h",
|
||||
"MGLVectorStyleLayer.h": "platform/darwin/src/MGLVectorStyleLayer.h",
|
||||
"MGLNetworkConfiguration.h": "platform/darwin/src/MGLNetworkConfiguration.h",
|
||||
"MGLComputedShapeSource.h": "platform/darwin/src/MGLComputedShapeSource.h",
|
||||
"MGLLoggingConfiguration.h": "platform/darwin/src/MGLLoggingConfiguration.h",
|
||||
"MGLLocationManager.h": "platform/darwin/src/MGLLocationManager.h",
|
||||
@@ -236,7 +237,6 @@
|
||||
"MGLLoggingConfiguration_Private.h": "platform/darwin/src/MGLLoggingConfiguration_Private.h",
|
||||
"NSComparisonPredicate+MGLAdditions.h": "platform/darwin/src/NSComparisonPredicate+MGLAdditions.h",
|
||||
"MGLMapAccessibilityElement.h": "platform/ios/src/MGLMapAccessibilityElement.h",
|
||||
"MGLNetworkConfiguration.h": "platform/darwin/src/MGLNetworkConfiguration.h",
|
||||
"MGLScaleBar.h": "platform/ios/src/MGLScaleBar.h",
|
||||
"NSString+MGLAdditions.h": "platform/darwin/src/NSString+MGLAdditions.h",
|
||||
"UIDevice+MGLAdditions.h": "platform/ios/src/UIDevice+MGLAdditions.h",
|
||||
|
||||
@@ -71,3 +71,4 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[];
|
||||
#import "NSPredicate+MGLAdditions.h"
|
||||
#import "MGLLocationManager.h"
|
||||
#import "MGLLoggingConfiguration.h"
|
||||
#import "MGLNetworkConfiguration.h"
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* Added an `MGLStyle.performsPlacementTransitions` property to control how long it takes for colliding labels to fade out. ([#13565](https://github.com/mapbox/mapbox-gl-native/pull/13565))
|
||||
* Fixed a crash when casting large numbers in `NSExpression`. ([#13580](https://github.com/mapbox/mapbox-gl-native/pull/13580))
|
||||
* Added the `-[MGLShapeSource leavesOfCluster:offset:limit:]`, `-[MGLShapeSource childrenOfCluster:]`, `-[MGLShapeSource zoomLevelForExpandingCluster:]` methods for inspecting a cluster in an `MGLShapeSource`s created with the `MGLShapeSourceOptionClustered` option. Feature querying now returns clusters represented by `MGLPointFeatureCluster` objects (that conform to the `MGLCluster` protocol). ([#12952](https://github.com/mapbox/mapbox-gl-native/pull/12952)
|
||||
* Added `MGLNetworkConfiguration` class to customize the SDK's `NSURLSessionConfiguration` object. ([#11447](https://github.com/mapbox/mapbox-gl-native/pull/13886))
|
||||
|
||||
### Annotations
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@
|
||||
DAF25716201901C200367EF5 /* MGLHillshadeStyleLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = DAF25714201901C200367EF5 /* MGLHillshadeStyleLayer.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
DAF25721201902C100367EF5 /* MGLHillshadeStyleLayerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DAF2571D201902A500367EF5 /* MGLHillshadeStyleLayerTests.mm */; };
|
||||
DD0902B21DB1AC6400C5BDCE /* MGLNetworkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0902AF1DB1AC6400C5BDCE /* MGLNetworkConfiguration.m */; };
|
||||
DD0902B31DB1AC6400C5BDCE /* MGLNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = DD0902B01DB1AC6400C5BDCE /* MGLNetworkConfiguration.h */; };
|
||||
DD0902B31DB1AC6400C5BDCE /* MGLNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = DD0902B01DB1AC6400C5BDCE /* MGLNetworkConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
DD58A4C91D822C6700E1F038 /* MGLExpressionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD58A4C71D822C6200E1F038 /* MGLExpressionTests.mm */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@
|
||||
"MGLFillStyleLayer.h": "platform/darwin/src/MGLFillStyleLayer.h",
|
||||
"MGLCoordinateFormatter.h": "platform/darwin/src/MGLCoordinateFormatter.h",
|
||||
"MGLShapeOfflineRegion.h": "platform/darwin/src/MGLShapeOfflineRegion.h",
|
||||
"MGLNetworkConfiguration.h": "platform/darwin/src/MGLNetworkConfiguration.h",
|
||||
"MGLOverlay.h": "platform/darwin/src/MGLOverlay.h",
|
||||
"MGLPolyline.h": "platform/darwin/src/MGLPolyline.h",
|
||||
"MGLLineStyleLayer.h": "platform/darwin/src/MGLLineStyleLayer.h",
|
||||
@@ -170,7 +171,6 @@
|
||||
"NSExpression+MGLPrivateAdditions.h": "platform/darwin/src/NSExpression+MGLPrivateAdditions.h",
|
||||
"NSCompoundPredicate+MGLAdditions.h": "platform/darwin/src/NSCompoundPredicate+MGLAdditions.h",
|
||||
"MGLSymbolStyleLayer_Private.h": "platform/darwin/src/MGLSymbolStyleLayer_Private.h",
|
||||
"MGLNetworkConfiguration.h": "platform/darwin/src/MGLNetworkConfiguration.h",
|
||||
"NSProcessInfo+MGLAdditions.h": "platform/darwin/src/NSProcessInfo+MGLAdditions.h",
|
||||
"MGLRendererFrontend.h": "platform/darwin/src/MGLRendererFrontend.h",
|
||||
"NSValue+MGLStyleAttributeAdditions.h": "platform/darwin/src/NSValue+MGLStyleAttributeAdditions.h",
|
||||
|
||||
@@ -66,3 +66,4 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[];
|
||||
#import "NSExpression+MGLAdditions.h"
|
||||
#import "NSPredicate+MGLAdditions.h"
|
||||
#import "MGLLoggingConfiguration.h"
|
||||
#import "MGLNetworkConfiguration.h"
|
||||
|
||||
Reference in New Issue
Block a user