diff options
Diffstat (limited to 'platform/darwin/src')
-rw-r--r-- | platform/darwin/src/NSURL+MGLAdditions.h | 17 | ||||
-rw-r--r-- | platform/darwin/src/NSURL+MGLAdditions.m | 21 |
2 files changed, 38 insertions, 0 deletions
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 <Foundation/Foundation.h> + +#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 |