From 1daba5d04b5f6a704a1ee608b64b7bb42101903f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 16 Aug 2016 01:17:11 -0700 Subject: [ios, macos] Accept absolute file paths as style URLs (#6026) It turns out that mbgl::AssetFileSource supports absolute file URLs in addition to relative file URLs. So replace the file: scheme with asset: while percent-escaping as necessary. Also added amsterdam.geojson to macos.xcodeproj for consistency with ios.xcodeproj. --- platform/darwin/src/NSURL+MGLAdditions.h | 17 +++++++++++++++++ platform/darwin/src/NSURL+MGLAdditions.m | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 platform/darwin/src/NSURL+MGLAdditions.h create mode 100644 platform/darwin/src/NSURL+MGLAdditions.m (limited to 'platform/darwin/src') diff --git a/platform/darwin/src/NSURL+MGLAdditions.h b/platform/darwin/src/NSURL+MGLAdditions.h new file mode 100644 index 0000000000..70fd79f064 --- /dev/null +++ b/platform/darwin/src/NSURL+MGLAdditions.h @@ -0,0 +1,17 @@ +#import + +#import "MGLTypes.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface NSURL (MGLAdditions) + +/** + Returns the given URL, modified if necessary to use the asset: URL scheme + expected by mbgl for local requests. + */ +- (nullable NSURL *)mgl_URLByStandardizingScheme; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSURL+MGLAdditions.m b/platform/darwin/src/NSURL+MGLAdditions.m new file mode 100644 index 0000000000..11b84ed8fa --- /dev/null +++ b/platform/darwin/src/NSURL+MGLAdditions.m @@ -0,0 +1,21 @@ +#import "NSURL+MGLAdditions.h" + +@implementation NSURL (MGLAdditions) + +- (nullable NSURL *)mgl_URLByStandardizingScheme { + if (!self.scheme) { + // Relative file URL, already escaped (in order to create the NSURL). + // Assume a relative path into the application’s resource folder. + return [NSURL URLWithString:[@"asset://" stringByAppendingString:self.absoluteString]]; + } else if (self.fileURL) { + // Absolute file URL, so construct a new URL using the unescaped path. + NSURLComponents *components = [[NSURLComponents alloc] init]; + components.scheme = @"asset"; + components.host = @""; + components.path = self.path; + return components.URL; + } + return self; +} + +@end -- cgit v1.2.1