From c06f8faae81721a195838857b94f0a8231d59566 Mon Sep 17 00:00:00 2001 From: m-stephen Date: Sat, 14 Dec 2019 13:38:46 +0800 Subject: [ios, macos]Remove iOS/macOS codes from native codes (#16031) * add source/header * add ios files * add configs * modify name * http_file_source * add interface delegate when map init * fix name * fix delegate name * support mac os * add mac os support * make optional delegate when mac os * mac/ios difference * add ios change log * cancel iOS/mac OS judgement * cancel iOS/mac OS judgement * cancel judgement in .m * update * update * update http_file_source * update ios * update mac os * add mac os file * add mac os file to `.cmake` * change names * add log & fix format * reset changelog commit * update changelog * rename iOS network manager * Add a test configuration(same as default configuration) when mac os run tests * re-add account type into `http_file_source` * refactor --- next/platform/macos/macos.cmake | 2 + .../mbgl/interface/native_apple_interface.h | 51 +++++++++++++++ platform/darwin/src/MGLNetworkIntegrationManager.h | 8 +++ platform/darwin/src/MGLNetworkIntegrationManager.m | 54 ++++++++++++++++ platform/darwin/src/http_file_source.mm | 31 ++++----- platform/darwin/src/native_apple_interface.m | 73 ++++++++++++++++++++++ platform/ios/core-files.json | 4 +- platform/ios/ios.xcodeproj/project.pbxproj | 20 ++++++ platform/ios/sdk-files.json | 2 + platform/ios/src/MGLMapView.mm | 2 + platform/macos/core-files.json | 4 +- platform/macos/macos.xcodeproj/project.pbxproj | 18 +++++- platform/macos/sdk-files.json | 2 + platform/macos/src/MGLMapView.mm | 2 + 14 files changed, 250 insertions(+), 23 deletions(-) create mode 100644 platform/darwin/include/mbgl/interface/native_apple_interface.h create mode 100644 platform/darwin/src/MGLNetworkIntegrationManager.h create mode 100644 platform/darwin/src/MGLNetworkIntegrationManager.m create mode 100644 platform/darwin/src/native_apple_interface.m diff --git a/next/platform/macos/macos.cmake b/next/platform/macos/macos.cmake index 721d19e625..380a341d93 100644 --- a/next/platform/macos/macos.cmake +++ b/next/platform/macos/macos.cmake @@ -88,6 +88,8 @@ target_sources( ${MBGL_ROOT}/platform/darwin/src/run_loop.cpp ${MBGL_ROOT}/platform/darwin/src/string_nsstring.mm ${MBGL_ROOT}/platform/darwin/src/timer.cpp + ${MBGL_ROOT}/platform/darwin/src/native_apple_interface.m + ${MBGL_ROOT}/platform/darwin/src/MGLNetworkIntegrationManager.m ${MBGL_ROOT}/platform/default/src/mbgl/gfx/headless_backend.cpp ${MBGL_ROOT}/platform/default/src/mbgl/gfx/headless_frontend.cpp ${MBGL_ROOT}/platform/default/src/mbgl/gl/headless_backend.cpp diff --git a/platform/darwin/include/mbgl/interface/native_apple_interface.h b/platform/darwin/include/mbgl/interface/native_apple_interface.h new file mode 100644 index 0000000000..d4d207462d --- /dev/null +++ b/platform/darwin/include/mbgl/interface/native_apple_interface.h @@ -0,0 +1,51 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol MGLNativeNetworkDelegate + +@optional + +- (NSString *)skuToken; + +@required + +- (NSURLSessionConfiguration *)sessionConfiguration; + +- (void)startDownloadEvent:(NSString *)event type:(NSString *)type; + +- (void)cancelDownloadEventForResponse:(NSURLResponse *)response; + +- (void)stopDownloadEventForResponse:(NSURLResponse *)response; + +- (void)debugLog:(NSString *)format, ...; + +- (void)errorLog:(NSString *)format, ...; + +@end + +#define MGL_APPLE_EXPORT __attribute__((visibility ("default"))) + +@interface MGLNativeNetworkManager: NSObject + ++ (MGLNativeNetworkManager *)sharedManager; + +@property (nonatomic, weak) id delegate; + +@property (nonatomic, readonly) NSString *skuToken; + +@property (nonatomic, readonly) NSURLSessionConfiguration *sessionConfiguration; + +- (void)startDownloadEvent:(NSString *)event type:(NSString *)type; + +- (void)cancelDownloadEventForResponse:(NSURLResponse *)response; + +- (void)stopDownloadEventForResponse:(NSURLResponse *)response; + +- (void)debugLog:(NSString *)format, ...; + +- (void)errorLog:(NSString *)format, ...; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLNetworkIntegrationManager.h b/platform/darwin/src/MGLNetworkIntegrationManager.h new file mode 100644 index 0000000000..2c929e16f8 --- /dev/null +++ b/platform/darwin/src/MGLNetworkIntegrationManager.h @@ -0,0 +1,8 @@ +#import +#include + +@interface MGLNetworkIntegrationManager : NSObject + ++ (MGLNetworkIntegrationManager *)sharedManager; + +@end diff --git a/platform/darwin/src/MGLNetworkIntegrationManager.m b/platform/darwin/src/MGLNetworkIntegrationManager.m new file mode 100644 index 0000000000..79c7f15156 --- /dev/null +++ b/platform/darwin/src/MGLNetworkIntegrationManager.m @@ -0,0 +1,54 @@ +#import "MGLNetworkIntegrationManager.h" + +#import "MGLLoggingConfiguration_Private.h" +#import "MGLNetworkConfiguration_Private.h" + +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +#import "MGLAccountManager_Private.h" +#endif + +@implementation MGLNetworkIntegrationManager + +static MGLNetworkIntegrationManager *instance = nil; + ++ (MGLNetworkIntegrationManager *)sharedManager { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + instance = [[MGLNetworkIntegrationManager alloc] init]; + }); + return instance; +} + +#pragma mark - MGLNativeAppleInterfaceManager delegate - + +- (NSURLSessionConfiguration *)sessionConfiguration { + return [MGLNetworkConfiguration sharedManager].sessionConfiguration; +} + +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +- (NSString *)skuToken { + return MGLAccountManager.skuToken; +} +#endif + +- (void)startDownloadEvent:(NSString *)event type:(NSString *)type { + [[MGLNetworkConfiguration sharedManager] startDownloadEvent:event type:@"tile"]; +} + +- (void)cancelDownloadEventForResponse:(NSURLResponse *)response { + [[MGLNetworkConfiguration sharedManager] cancelDownloadEventForResponse:response]; +} + +- (void)stopDownloadEventForResponse:(NSURLResponse *)response { + [[MGLNetworkConfiguration sharedManager] stopDownloadEventForResponse:response]; +} + +- (void)debugLog:(NSString *)format, ... { + MGLLogDebug(format); +} + +- (void)errorLog:(NSString *)format, ... { + MGLLogError(format); +} + +@end diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index dbf92aa462..6f68111203 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -8,12 +8,7 @@ #import -#import "MGLLoggingConfiguration_Private.h" -#import "MGLNetworkConfiguration_Private.h" - -#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR -#import "MGLAccountManager_Private.h" -#endif +#include #include #include @@ -88,14 +83,10 @@ class HTTPFileSource::Impl { public: Impl() { @autoreleasepool { - NSURLSessionConfiguration *sessionConfig = [MGLNetworkConfiguration sharedManager].sessionConfiguration; + NSURLSessionConfiguration *sessionConfig = MGLNativeNetworkManager.sharedManager.sessionConfiguration; session = [NSURLSession sessionWithConfiguration:sessionConfig]; userAgent = getUserAgent(); - -#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR - accountType = [[NSUserDefaults standardUserDefaults] integerForKey:MGLMapboxAccountTypeKey]; -#endif } } @@ -195,7 +186,7 @@ HTTPFileSource::HTTPFileSource() HTTPFileSource::~HTTPFileSource() = default; -MGL_EXPORT +MGL_APPLE_EXPORT BOOL isValidMapboxEndpoint(NSURL *url) { return ([url.host isEqualToString:@"mapbox.com"] || [url.host hasSuffix:@".mapbox.com"] || @@ -203,7 +194,7 @@ BOOL isValidMapboxEndpoint(NSURL *url) { [url.host hasSuffix:@".mapbox.cn"]); } -MGL_EXPORT +MGL_APPLE_EXPORT NSURL *resourceURLWithAccountType(const Resource& resource, NSInteger accountType) { NSURL *url = [NSURL URLWithString:@(resource.url.c_str())]; @@ -217,7 +208,7 @@ NSURL *resourceURLWithAccountType(const Resource& resource, NSInteger accountTyp [queryItems addObject:[NSURLQueryItem queryItemWithName:@"offline" value:@"true"]]; } else { // Only add SKU token to requests not tagged as "offline" usage. - [queryItems addObject:[NSURLQueryItem queryItemWithName:@"sku" value:MGLAccountManager.skuToken]]; + [queryItems addObject:[NSURLQueryItem queryItemWithName:@"sku" value:MGLNativeNetworkManager.sharedManager.skuToken]]; } if (components.queryItems) { @@ -239,7 +230,7 @@ std::unique_ptr HTTPFileSource::request(const Resource& resource, @autoreleasepool { NSURL *url = resourceURLWithAccountType(resource, impl->accountType); - MGLLogDebug(@"Requesting URI: %@", url.relativePath); + [MGLNativeNetworkManager.sharedManager debugLog:@"Requesting URI: %@", url.relativePath]; NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; if (resource.priorEtag) { @@ -255,22 +246,22 @@ std::unique_ptr HTTPFileSource::request(const Resource& resource, const bool isTile = resource.kind == mbgl::Resource::Kind::Tile; if (isTile) { - [[MGLNetworkConfiguration sharedManager] startDownloadEvent:url.relativePath type:@"tile"]; + [MGLNativeNetworkManager.sharedManager startDownloadEvent:url.relativePath type:@"tile"]; } request->task = [impl->session dataTaskWithRequest:req completionHandler:^(NSData* data, NSURLResponse* res, NSError* error) { if (error && [error code] == NSURLErrorCancelled) { - [[MGLNetworkConfiguration sharedManager] cancelDownloadEventForResponse:res]; + [MGLNativeNetworkManager.sharedManager cancelDownloadEventForResponse:res]; return; } - [[MGLNetworkConfiguration sharedManager] stopDownloadEventForResponse:res]; + [MGLNativeNetworkManager.sharedManager stopDownloadEventForResponse:res]; Response response; using Error = Response::Error; if (error) { - MGLLogError(@"Requesting: %@ failed with error: %@", res.URL.relativePath, error); + [MGLNativeNetworkManager.sharedManager errorLog:@"Requesting: %@ failed with error: %@", res.URL.relativePath, error]; if (data) { response.data = @@ -303,7 +294,7 @@ std::unique_ptr HTTPFileSource::request(const Resource& resource, } } else if ([res isKindOfClass:[NSHTTPURLResponse class]]) { const long responseCode = [(NSHTTPURLResponse *)res statusCode]; - MGLLogDebug(@"Requesting %@ returned responseCode: %lu", res.URL.relativePath, responseCode); + [MGLNativeNetworkManager.sharedManager debugLog:@"Requesting %@ returned responseCode: %lu", res.URL.relativePath, responseCode]; NSDictionary *headers = [(NSHTTPURLResponse *)res allHeaderFields]; NSString *cache_control = [headers objectForKey:@"Cache-Control"]; diff --git a/platform/darwin/src/native_apple_interface.m b/platform/darwin/src/native_apple_interface.m new file mode 100644 index 0000000000..07dce0d5b0 --- /dev/null +++ b/platform/darwin/src/native_apple_interface.m @@ -0,0 +1,73 @@ +#import +#import + +@implementation MGLNativeNetworkManager + +static MGLNativeNetworkManager *instance = nil; + ++ (MGLNativeNetworkManager *)sharedManager { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + instance = [[MGLNativeNetworkManager alloc] init]; + }); + return instance; +} + +- (NSURLSessionConfiguration *)sessionConfiguration { + if (_delegate && [_delegate respondsToSelector:@selector(sessionConfiguration)]) { + return [_delegate sessionConfiguration]; + } + // For testing. Since we get a `nil` return when SDK is modualar, we use this for testing requests. + // Same as `[MGLNetworkConfiguration defaultSessionConfiguration]` in `MGLNetworkConfiguration.m`. + return [self testSessionConfiguration]; +} + +- (NSURLSessionConfiguration *)testSessionConfiguration { + NSURLSessionConfiguration* sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; + + sessionConfiguration.timeoutIntervalForResource = 30; + sessionConfiguration.HTTPMaximumConnectionsPerHost = 8; + sessionConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData; + sessionConfiguration.URLCache = nil; + + return sessionConfiguration; +} + +- (NSString *)skuToken { + if(_delegate && [_delegate respondsToSelector:@selector(skuToken)]) { + return [_delegate skuToken]; + } + return nil; +} + +- (void)startDownloadEvent:(NSString *)event type:(NSString *)type { + if (_delegate && [_delegate respondsToSelector:@selector(startDownloadEvent:type:)]) { + [_delegate startDownloadEvent:event type:type]; + } +} + +- (void)cancelDownloadEventForResponse:(NSURLResponse *)response { + if (_delegate && [_delegate respondsToSelector:@selector(cancelDownloadEventForResponse:)]) { + return [_delegate cancelDownloadEventForResponse:response]; + } +} + +- (void)stopDownloadEventForResponse:(NSURLResponse *)response { + if (_delegate && [_delegate respondsToSelector:@selector(stopDownloadEventForResponse:)]) { + return [_delegate stopDownloadEventForResponse:response]; + } +} + +- (void)debugLog:(NSString *)format, ...{ + if (_delegate && [_delegate respondsToSelector:@selector(debugLog:)]) { + return [_delegate debugLog:format]; + } +} + +- (void)errorLog:(NSString *)format, ...{ + if (_delegate && [_delegate respondsToSelector:@selector(errorLog:)]) { + return [_delegate errorLog:format]; + } +} + +@end diff --git a/platform/ios/core-files.json b/platform/ios/core-files.json index 08cf1b5946..44b3cf76aa 100644 --- a/platform/ios/core-files.json +++ b/platform/ios/core-files.json @@ -20,10 +20,12 @@ "platform/default/src/mbgl/util/monotonic_timer.cpp", "platform/default/src/mbgl/util/png_writer.cpp", "platform/default/src/mbgl/util/thread_local.cpp", - "platform/default/src/mbgl/util/utf.cpp" + "platform/default/src/mbgl/util/utf.cpp", + "platform/darwin/src/native_apple_interface.m" ], "public_headers": { "mbgl/storage/reachability.h": "platform/darwin/include/mbgl/storage/reachability.h", + "mbgl/interface/native_apple_interface.h": "platform/darwin/include/mbgl/interface/native_apple_interface.h", "mbgl/util/image+MGLAdditions.hpp": "platform/darwin/include/mbgl/util/image+MGLAdditions.hpp", "mbgl/gfx/headless_backend.hpp": "platform/default/include/mbgl/gfx/headless_backend.hpp", "mbgl/gfx/headless_frontend.hpp": "platform/default/include/mbgl/gfx/headless_frontend.hpp", diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 350a8014fd..4db9409081 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -534,6 +534,10 @@ CAFB3C15234505D500399265 /* MGLMapSnapshotter_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = CAFB3C13234505D500399265 /* MGLMapSnapshotter_Private.h */; }; CF75A91522D85E860058A5C4 /* MGLLoggingConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = CF75A91422D85E860058A5C4 /* MGLLoggingConfiguration.mm */; }; CF75A91622D85E860058A5C4 /* MGLLoggingConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = CF75A91422D85E860058A5C4 /* MGLLoggingConfiguration.mm */; }; + CFF9F98623A24BF500B0DE92 /* MGLNetworkIntegrationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = CFF9F98423A24BF400B0DE92 /* MGLNetworkIntegrationManager.h */; }; + CFF9F98723A24BF500B0DE92 /* MGLNetworkIntegrationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = CFF9F98423A24BF400B0DE92 /* MGLNetworkIntegrationManager.h */; }; + CFF9F98823A24BF500B0DE92 /* MGLNetworkIntegrationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CFF9F98523A24BF400B0DE92 /* MGLNetworkIntegrationManager.m */; }; + CFF9F98923A24BF500B0DE92 /* MGLNetworkIntegrationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CFF9F98523A24BF400B0DE92 /* MGLNetworkIntegrationManager.m */; }; DA00FC8E1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8F1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC901D5EEB0D009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */; }; @@ -1226,6 +1230,8 @@ CAE7AD5420F46EF5003B6782 /* MGLMapSnapshotterSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MGLMapSnapshotterSwiftTests.swift; sourceTree = ""; }; CAFB3C13234505D500399265 /* MGLMapSnapshotter_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLMapSnapshotter_Private.h; sourceTree = ""; }; CF75A91422D85E860058A5C4 /* MGLLoggingConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLLoggingConfiguration.mm; sourceTree = ""; }; + CFF9F98423A24BF400B0DE92 /* MGLNetworkIntegrationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MGLNetworkIntegrationManager.h; path = ../../darwin/src/MGLNetworkIntegrationManager.h; sourceTree = ""; }; + CFF9F98523A24BF400B0DE92 /* MGLNetworkIntegrationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLNetworkIntegrationManager.m; path = ../../darwin/src/MGLNetworkIntegrationManager.m; sourceTree = ""; }; DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = ""; }; DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = ""; }; DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; @@ -1961,6 +1967,15 @@ name = Annotations; sourceTree = ""; }; + CF85C39E23A249FC00BEBFFF /* Interface */ = { + isa = PBXGroup; + children = ( + CFF9F98423A24BF400B0DE92 /* MGLNetworkIntegrationManager.h */, + CFF9F98523A24BF400B0DE92 /* MGLNetworkIntegrationManager.m */, + ); + name = Interface; + sourceTree = ""; + }; DA1DC9411CB6C1C2006E619F = { isa = PBXGroup; children = ( @@ -2188,6 +2203,7 @@ DA8848331CBAFB2A00AB86E3 /* Kit */ = { isa = PBXGroup; children = ( + CF85C39E23A249FC00BEBFFF /* Interface */, DAD165841CF4D06B001FF4B9 /* Annotations */, 35CE617F1D4165C2004F2359 /* Categories */, DA8848881CBB036000AB86E3 /* SMCalloutView */, @@ -2632,6 +2648,7 @@ 55E5665B21C2A2080008B8B5 /* MMEEventLogger.h in Headers */, 55E5665C21C2A2080008B8B5 /* MMEEventLogReportViewController.h in Headers */, 55E5665D21C2A2080008B8B5 /* MMEEventsConfiguration.h in Headers */, + CFF9F98623A24BF500B0DE92 /* MGLNetworkIntegrationManager.h in Headers */, 55E5666021C2A2080008B8B5 /* MMEConfigurator.h in Headers */, 55E5666221C2A2080008B8B5 /* MMELocationManager.h in Headers */, 55E5666321C2A2080008B8B5 /* MMEMetrics.h in Headers */, @@ -2826,6 +2843,7 @@ 35D13AC41D3D19DD00AFB4E0 /* MGLFillStyleLayer.h in Headers */, 9C6E284322A982670056B7BE /* MMETypes.h in Headers */, DABFB86E1CBE9A0F00D62B32 /* MGLCalloutView.h in Headers */, + CFF9F98723A24BF500B0DE92 /* MGLNetworkIntegrationManager.h in Headers */, 96E516FC20005A4400A02306 /* MGLUserLocationHeadingIndicator.h in Headers */, 1F7454971ECD450D00021D39 /* MGLLight_Private.h in Headers */, 9C6E283C22A982670056B7BE /* MMEEventsManager.h in Headers */, @@ -3406,6 +3424,7 @@ 35136D451D42275100C20EFD /* MGLSymbolStyleLayer.mm in Sources */, CF75A91522D85E860058A5C4 /* MGLLoggingConfiguration.mm in Sources */, 35599DED1D46F14E0048254D /* MGLStyleValue.mm in Sources */, + CFF9F98823A24BF500B0DE92 /* MGLNetworkIntegrationManager.m in Sources */, DA8848211CBAFA6200AB86E3 /* MGLOfflinePack.mm in Sources */, 0778DD441F67556C00A73B34 /* MGLComputedShapeSource.mm in Sources */, 3557F7B21E1D27D300CCA5E6 /* MGLDistanceFormatter.m in Sources */, @@ -3533,6 +3552,7 @@ DAA4E4261CBB730400178DFB /* MGLStyle.mm in Sources */, CF75A91622D85E860058A5C4 /* MGLLoggingConfiguration.mm in Sources */, DAA32CC31E4C6B65006F8D24 /* MGLDistanceFormatter.m in Sources */, + CFF9F98923A24BF500B0DE92 /* MGLNetworkIntegrationManager.m in Sources */, DAA4E41D1CBB730400178DFB /* MGLGeometry.mm in Sources */, 40834BFB1FE05E1800C1BD0D /* MMEAPIClient.m in Sources */, 1FCCEC37222605C400302E3B /* MGLSDKMetricsManager.m in Sources */, diff --git a/platform/ios/sdk-files.json b/platform/ios/sdk-files.json index dc59e179c8..47dacb7cce 100644 --- a/platform/ios/sdk-files.json +++ b/platform/ios/sdk-files.json @@ -60,6 +60,7 @@ "platform/darwin/src/MGLSymbolStyleLayer.mm", "platform/darwin/src/MGLLoggingConfiguration.mm", "platform/darwin/src/MGLStyleValue.mm", + "platform/darwin/src/MGLNetworkIntegrationManager.m", "platform/darwin/src/MGLOfflinePack.mm", "platform/darwin/src/MGLComputedShapeSource.mm", "platform/darwin/src/MGLDistanceFormatter.m", @@ -298,6 +299,7 @@ "MMEEventLogger.h": "platform/ios/vendor/mapbox-events-ios/MapboxMobileEvents/MMEEventLogger.h", "MMEEventLogReportViewController.h": "platform/ios/vendor/mapbox-events-ios/MapboxMobileEvents/MMEEventLogReportViewController.h", "MMEEventsConfiguration.h": "platform/ios/vendor/mapbox-events-ios/MapboxMobileEvents/MMEEventsConfiguration.h", + "MGLNetworkIntegrationManager.h": "platform/darwin/src/MGLNetworkIntegrationManager.h", "MMEConfigurator.h": "platform/ios/vendor/mapbox-events-ios/MapboxMobileEvents/MMEConfigurator.h", "MMELocationManager.h": "platform/ios/vendor/mapbox-events-ios/MapboxMobileEvents/MMELocationManager.h", "MMEMetrics.h": "platform/ios/vendor/mapbox-events-ios/MapboxMobileEvents/MMEMetrics.h", diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 9b4ef8ff2d..d8470aa999 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -68,6 +68,7 @@ #import "MGLMapAccessibilityElement.h" #import "MGLLocationManager_Private.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLNetworkIntegrationManager.h" #import "MMEConstants.h" #include @@ -452,6 +453,7 @@ public: // setup accessibility // // self.isAccessibilityElement = YES; + MGLNativeNetworkManager.sharedManager.delegate = MGLNetworkIntegrationManager.sharedManager; self.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"MAP_A11Y_LABEL", nil, nil, @"Map", @"Accessibility label"); self.accessibilityTraits = UIAccessibilityTraitAllowsDirectInteraction | UIAccessibilityTraitAdjustable; self.backgroundColor = [UIColor clearColor]; diff --git a/platform/macos/core-files.json b/platform/macos/core-files.json index 5fde52876a..9472721e8b 100644 --- a/platform/macos/core-files.json +++ b/platform/macos/core-files.json @@ -19,10 +19,12 @@ "platform/default/src/mbgl/util/monotonic_timer.cpp", "platform/default/src/mbgl/util/png_writer.cpp", "platform/default/src/mbgl/util/thread_local.cpp", - "platform/default/src/mbgl/util/utf.cpp" + "platform/default/src/mbgl/util/utf.cpp", + "platform/darwin/src/native_apple_interface.m" ], "public_headers": { "mbgl/storage/reachability.h": "platform/darwin/include/mbgl/storage/reachability.h", + "mbgl/interface/native_apple_interface.h": "platform/darwin/include/mbgl/interface/native_apple_interface.h", "mbgl/util/image+MGLAdditions.hpp": "platform/darwin/include/mbgl/util/image+MGLAdditions.hpp", "mbgl/gfx/headless_backend.hpp": "platform/default/include/mbgl/gfx/headless_backend.hpp", "mbgl/gfx/headless_frontend.hpp": "platform/default/include/mbgl/gfx/headless_frontend.hpp", diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 226bc62312..7dcd72b47d 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -135,6 +135,8 @@ CA9461A620884CCB0015EB12 /* MGLAnnotationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA9461A520884CCB0015EB12 /* MGLAnnotationTests.m */; }; CAD9D0AC22A88A32001B25EE /* MGLResourceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = CAD9D0AB22A88A32001B25EE /* MGLResourceTests.mm */; }; CF762DEF22DC7EFF00338472 /* MGLLoggingConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = CF762DEE22DC7EFF00338472 /* MGLLoggingConfiguration.mm */; }; + CFF9F98D23A2505700B0DE92 /* MGLNetworkIntegrationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CFF9F98B23A2505700B0DE92 /* MGLNetworkIntegrationManager.m */; }; + CFF9F98E23A2505700B0DE92 /* MGLNetworkIntegrationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = CFF9F98C23A2505700B0DE92 /* MGLNetworkIntegrationManager.h */; }; DA00FC8A1D5EEAC3009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8B1D5EEAC3009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */; }; DA0CD58E1CF56F5800A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */; }; @@ -425,7 +427,7 @@ 5591AC692298361600FF9ADF /* MGLMapView+Impl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "MGLMapView+Impl.mm"; sourceTree = ""; }; 55CAF6312294407F00F17770 /* MGLMapView+OpenGL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MGLMapView+OpenGL.h"; sourceTree = ""; }; 55CAF6332294409B00F17770 /* MGLMapView+OpenGL.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "MGLMapView+OpenGL.mm"; sourceTree = ""; }; - 55CF7532213EDADF00ED86C4 /* libmbgl-vendor-icu.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libmbgl-vendor-icu.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 55CF7532213EDADF00ED86C4 /* libmbgl-vendor-icu.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = "libmbgl-vendor-icu.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 55D120A41F7906E6004B6D81 /* libmbgl-filesource.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = "libmbgl-filesource.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 55D9B4B01D005D3900C1CCE2 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 55E2AD101E5B0A6900E8C587 /* MGLOfflineStorageTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLOfflineStorageTests.mm; path = ../../darwin/test/MGLOfflineStorageTests.mm; sourceTree = ""; }; @@ -476,6 +478,8 @@ CA9461A520884CCB0015EB12 /* MGLAnnotationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLAnnotationTests.m; path = test/MGLAnnotationTests.m; sourceTree = SOURCE_ROOT; }; CAD9D0AB22A88A32001B25EE /* MGLResourceTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLResourceTests.mm; path = ../../darwin/test/MGLResourceTests.mm; sourceTree = ""; }; CF762DEE22DC7EFF00338472 /* MGLLoggingConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLLoggingConfiguration.mm; sourceTree = ""; }; + CFF9F98B23A2505700B0DE92 /* MGLNetworkIntegrationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLNetworkIntegrationManager.m; path = ../../darwin/src/MGLNetworkIntegrationManager.m; sourceTree = ""; }; + CFF9F98C23A2505700B0DE92 /* MGLNetworkIntegrationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MGLNetworkIntegrationManager.h; path = ../../darwin/src/MGLNetworkIntegrationManager.h; sourceTree = ""; }; DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = ""; }; DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = ""; }; DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; @@ -880,6 +884,15 @@ name = "Test Helpers"; sourceTree = ""; }; + CFF9F98A23A2503300B0DE92 /* Interface */ = { + isa = PBXGroup; + children = ( + CFF9F98C23A2505700B0DE92 /* MGLNetworkIntegrationManager.h */, + CFF9F98B23A2505700B0DE92 /* MGLNetworkIntegrationManager.m */, + ); + name = Interface; + sourceTree = ""; + }; DA33895E1FA3E997001EA329 /* Recovered References */ = { isa = PBXGroup; children = ( @@ -1267,6 +1280,7 @@ DAE6C39E1CC31E7C00DB3429 /* Kit */ = { isa = PBXGroup; children = ( + CFF9F98A23A2503300B0DE92 /* Interface */, DA90B12C1DB43B180073CF55 /* Categories */, DAE6C39F1CC31E9400DB3429 /* MGLAnnotationImage.h */, DAC2ABC41CC6D343006D18C4 /* MGLAnnotationImage_Private.h */, @@ -1356,6 +1370,7 @@ DA7DC9811DED5F5C0027472F /* MGLVectorTileSource_Private.h in Headers */, DAE6C3861CC31E2A00DB3429 /* MGLGeometry_Private.h in Headers */, DAE6C3841CC31E2A00DB3429 /* MGLAccountManager_Private.h in Headers */, + CFF9F98E23A2505700B0DE92 /* MGLNetworkIntegrationManager.h in Headers */, DACA8622201920BE00E9693A /* MGLRasterDEMSource.h in Headers */, DAE6C3691CC31E0400DB3429 /* MGLTypes.h in Headers */, 07D9474D1F67441B00E37934 /* MGLComputedShapeSource_Private.h in Headers */, @@ -1688,6 +1703,7 @@ 408AA86A1DAEEE5D00022900 /* NSDictionary+MGLAdditions.mm in Sources */, DA8F25881D51C9E10010E6B5 /* MGLBackgroundStyleLayer.mm in Sources */, DA551B841DB496AC0009AFAF /* MGLTileSource.mm in Sources */, + CFF9F98D23A2505700B0DE92 /* MGLNetworkIntegrationManager.m in Sources */, DAE6C3B81CC31EF300DB3429 /* MGLMapView+IBAdditions.mm in Sources */, DA35A2D01CCAAED300E826B2 /* NSValue+MGLAdditions.m in Sources */, 3538AA241D542685008EC33D /* MGLStyleLayer.mm in Sources */, diff --git a/platform/macos/sdk-files.json b/platform/macos/sdk-files.json index 13760da70f..65b946cd06 100644 --- a/platform/macos/sdk-files.json +++ b/platform/macos/sdk-files.json @@ -37,6 +37,7 @@ "platform/darwin/src/NSDictionary+MGLAdditions.mm", "platform/darwin/src/MGLBackgroundStyleLayer.mm", "platform/darwin/src/MGLTileSource.mm", + "platform/darwin/src/MGLNetworkIntegrationManager.m", "platform/macos/src/MGLMapView+IBAdditions.mm", "platform/darwin/src/NSValue+MGLAdditions.m", "platform/darwin/src/MGLStyleLayer.mm", @@ -171,6 +172,7 @@ "MGLVectorTileSource_Private.h": "platform/darwin/src/MGLVectorTileSource_Private.h", "MGLGeometry_Private.h": "platform/darwin/src/MGLGeometry_Private.h", "MGLAccountManager_Private.h": "platform/darwin/src/MGLAccountManager_Private.h", + "MGLNetworkIntegrationManager.h": "platform/darwin/src/MGLNetworkIntegrationManager.h", "MGLComputedShapeSource_Private.h": "platform/darwin/src/MGLComputedShapeSource_Private.h", "NSException+MGLAdditions.h": "platform/darwin/src/NSException+MGLAdditions.h", "MGLTileSource_Private.h": "platform/darwin/src/MGLTileSource_Private.h", diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 9a7cb437ec..aec9cea0bc 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -57,6 +57,7 @@ #import "NSImage+MGLAdditions.h" #import "NSPredicate+MGLPrivateAdditions.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLNetworkIntegrationManager.h" class MGLAnnotationContext; @@ -258,6 +259,7 @@ public: } - (void)commonInit { + MGLNativeNetworkManager.sharedManager.delegate = MGLNetworkIntegrationManager.sharedManager; _isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent; // Set up cross-platform controllers and resources. -- cgit v1.2.1