diff --git a/URLHandler.js b/URLHandler.js index 6b81f29..50eacab 100644 --- a/URLHandler.js +++ b/URLHandler.js @@ -46,10 +46,8 @@ var URLHandler = { * without a host are treated as in-app URLs. */ openURL(targetURL: string) { - // Parse the query string and have "//" denote the hostname - var components = url.parse(targetURL, false, true); - if (components.protocol === 'xxx:') { - emitter.emit('request', url); + if (this.isInternalURL(targetURL)) { + emitter.emit('request', targetURL); } else { NTURLHandler.openURL(targetURL, () => {}, (error) => { console.error('Error opening URL: ' + error.stack); @@ -57,6 +55,19 @@ var URLHandler = { } }, + /** + * Returns whether the given URL is an in-app URL or an external URL. + */ + isInternalURL(targetURL: string): bool { + // Parse the query string and have "//" denote the hostname + var {protocol} = url.parse(targetURL, false, true); + if (!protocol) { + return true; + } + var scheme = protocol.substring(0, protocol.length - 1); + return this.schemes.indexOf(scheme) !== -1; + }, + /** * Adds a listener that receives an object with URL information when the app * has been instructed to open a URL. See the Request type. diff --git a/iOS/NTURLHandler/NTURLHandler.m b/iOS/NTURLHandler/NTURLHandler.m index d12244c..e23daa0 100644 --- a/iOS/NTURLHandler/NTURLHandler.m +++ b/iOS/NTURLHandler/NTURLHandler.m @@ -74,7 +74,9 @@ static NSString * const NTURLHandlerOpenURLNotification = @"NTURLHandlerOpenURL" NSMutableSet *schemes = [NSMutableSet set]; NSDictionary *info = [NSBundle mainBundle].infoDictionary; for (NSDictionary *urlType in info[@"CFBundleURLTypes"]) { - [schemes addObjectsFromArray:urlType[@"CFBundleURLSchemes"]]; + for (NSString *scheme in urlType[@"CFBundleURLSchemes"]) { + [schemes addObject:scheme.lowercaseString]; + } } return schemes; }