diff options
author | M.Stephen <truestyle2005@163.com> | 2019-12-13 16:37:47 +0800 |
---|---|---|
committer | M.Stephen <truestyle2005@163.com> | 2019-12-13 16:37:47 +0800 |
commit | 17d3e53b241c4af7fa3d4c8355351a8d764b4583 (patch) | |
tree | 859abbd6899288e9ad190c519b1cfa28bf6d4d53 | |
parent | 6aeb46cfefc56bcf79a34d8bce29a5fcfc02165c (diff) | |
download | qtlocation-mapboxgl-17d3e53b241c4af7fa3d4c8355351a8d764b4583.tar.gz |
add log & fix format
-rw-r--r-- | platform/darwin/include/mbgl/interface/native_apple_interface.h | 9 | ||||
-rw-r--r-- | platform/darwin/src/MGLNetworkIntegrationManager.h | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLNetworkIntegrationManager.m | 12 | ||||
-rw-r--r-- | platform/darwin/src/http_file_source.mm | 38 | ||||
-rw-r--r-- | platform/darwin/src/native_apple_interface.m | 19 |
5 files changed, 41 insertions, 39 deletions
diff --git a/platform/darwin/include/mbgl/interface/native_apple_interface.h b/platform/darwin/include/mbgl/interface/native_apple_interface.h index 8d929e9714..d4d207462d 100644 --- a/platform/darwin/include/mbgl/interface/native_apple_interface.h +++ b/platform/darwin/include/mbgl/interface/native_apple_interface.h @@ -7,7 +7,6 @@ NS_ASSUME_NONNULL_BEGIN @optional - (NSString *)skuToken; -- (NSString *)accountTypeKey; @required @@ -19,6 +18,10 @@ NS_ASSUME_NONNULL_BEGIN - (void)stopDownloadEventForResponse:(NSURLResponse *)response; +- (void)debugLog:(NSString *)format, ...; + +- (void)errorLog:(NSString *)format, ...; + @end #define MGL_APPLE_EXPORT __attribute__((visibility ("default"))) @@ -29,7 +32,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, weak) id<MGLNativeNetworkDelegate> delegate; -@property (nonatomic, readonly) NSString *accountTypeKey; @property (nonatomic, readonly) NSString *skuToken; @property (nonatomic, readonly) NSURLSessionConfiguration *sessionConfiguration; @@ -40,6 +42,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)stopDownloadEventForResponse:(NSURLResponse *)response; +- (void)debugLog:(NSString *)format, ...; + +- (void)errorLog:(NSString *)format, ...; @end diff --git a/platform/darwin/src/MGLNetworkIntegrationManager.h b/platform/darwin/src/MGLNetworkIntegrationManager.h index 450a52af91..2c929e16f8 100644 --- a/platform/darwin/src/MGLNetworkIntegrationManager.h +++ b/platform/darwin/src/MGLNetworkIntegrationManager.h @@ -1,7 +1,7 @@ #import <Foundation/Foundation.h> #include <mbgl/interface/native_apple_interface.h> -@interface MGLNetworkIntegrationManager : NSObject <MGLNativeAppleInterfaceDelegate> +@interface MGLNetworkIntegrationManager : NSObject <MGLNativeNetworkDelegate> + (MGLNetworkIntegrationManager *)sharedManager; diff --git a/platform/darwin/src/MGLNetworkIntegrationManager.m b/platform/darwin/src/MGLNetworkIntegrationManager.m index c133fe1223..79c7f15156 100644 --- a/platform/darwin/src/MGLNetworkIntegrationManager.m +++ b/platform/darwin/src/MGLNetworkIntegrationManager.m @@ -26,10 +26,6 @@ static MGLNetworkIntegrationManager *instance = nil; } #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR -- (NSString *)accountTypeKey { - return MGLMapboxAccountTypeKey; -} - - (NSString *)skuToken { return MGLAccountManager.skuToken; } @@ -47,4 +43,12 @@ static MGLNetworkIntegrationManager *instance = nil; [[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..10aae556c3 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -8,12 +8,7 @@ #import <Foundation/Foundation.h> -#import "MGLLoggingConfiguration_Private.h" -#import "MGLNetworkConfiguration_Private.h" - -#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR -#import "MGLAccountManager_Private.h" -#endif +#include <mbgl/interface/native_apple_interface.h> #include <mutex> #include <chrono> @@ -88,20 +83,15 @@ 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 } } NSURLSession* session = nil; NSString* userAgent = nil; - NSInteger accountType = 0; private: NSString* getUserAgent() const; @@ -195,7 +185,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,13 +193,13 @@ BOOL isValidMapboxEndpoint(NSURL *url) { [url.host hasSuffix:@".mapbox.cn"]); } -MGL_EXPORT -NSURL *resourceURLWithAccountType(const Resource& resource, NSInteger accountType) { +MGL_APPLE_EXPORT +NSURL *resourceURLWithAccountType(const Resource& resource) { NSURL *url = [NSURL URLWithString:@(resource.url.c_str())]; #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR - if (accountType == 0 && isValidMapboxEndpoint(url)) { + if (isValidMapboxEndpoint(url)) { NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; NSMutableArray *queryItems = [NSMutableArray array]; @@ -227,8 +217,6 @@ NSURL *resourceURLWithAccountType(const Resource& resource, NSInteger accountTyp components.queryItems = queryItems; url = components.URL; } -#else - (void)accountType; #endif return url; } @@ -238,8 +226,8 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, auto shared = request->shared; // Explicit copy so that it also gets copied into the completion handler block below. @autoreleasepool { - NSURL *url = resourceURLWithAccountType(resource, impl->accountType); - MGLLogDebug(@"Requesting URI: %@", url.relativePath); + NSURL *url = resourceURLWithAccountType(resource); + [MGLNativeNetworkManager.sharedManager debugLog:@"Requesting URI: %@", url.relativePath]; NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; if (resource.priorEtag) { @@ -255,22 +243,22 @@ std::unique_ptr<AsyncRequest> 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 +291,7 @@ std::unique_ptr<AsyncRequest> 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 index 7c83ec571d..fcc83a6475 100644 --- a/platform/darwin/src/native_apple_interface.m +++ b/platform/darwin/src/native_apple_interface.m @@ -27,13 +27,6 @@ static MGLNativeNetworkManager *instance = nil; return nil; } -- (NSString *)accountTypeKey { - if (_delegate && [_delegate respondsToSelector:@selector(accountTypeKey)]) { - return [_delegate accountTypeKey]; - } - return nil; -} - - (void)startDownloadEvent:(NSString *)event type:(NSString *)type { if (_delegate && [_delegate respondsToSelector:@selector(startDownloadEvent:type:)]) { [_delegate startDownloadEvent:event type:type]; @@ -52,4 +45,16 @@ static MGLNativeNetworkManager *instance = nil; } } +- (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 |