This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
14 changed files
with
250 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
platform/darwin/include/mbgl/interface/native_apple_interface.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@protocol MGLNativeNetworkDelegate <NSObject> | ||
|
||
@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<MGLNativeNetworkDelegate> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#import <Foundation/Foundation.h> | ||
#include <mbgl/interface/native_apple_interface.h> | ||
|
||
@interface MGLNetworkIntegrationManager : NSObject <MGLNativeNetworkDelegate> | ||
|
||
+ (MGLNetworkIntegrationManager *)sharedManager; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <mbgl/interface/native_apple_interface.h> | ||
|
||
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.