mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 22:37:14 +08:00
Allow linking to non-http/https system schemes
Summary: If you try linking to a system URL scheme that isn't http or https such a tel, the linking promise will be rejected. I'm fixing this by relying on the output of `BOOL canOpen = [RCTSharedApplication() canOpenURL:URL];` to resolve the promise, but still falling back on the better error message if the given URL cannot be opened. Changelog: [iOS][fixed] - Allow linking to system URL schemes other than http or https Reviewed By: cpojer Differential Revision: D14250507 fbshipit-source-id: d74b2bd615eb6e320a39a956424e0ee34d476dab
This commit is contained in:
committed by
Facebook Github Bot
parent
14a3a019ef
commit
fceba0cabe
@@ -120,20 +120,20 @@ RCT_EXPORT_METHOD(canOpenURL:(NSURL *)URL
|
||||
|
||||
// This can be expensive, so we deliberately don't call on main thread
|
||||
BOOL canOpen = [RCTSharedApplication() canOpenURL:URL];
|
||||
|
||||
NSString *scheme = [URL scheme];
|
||||
|
||||
// On iOS 9 and above canOpenURL returns NO without a helpful error.
|
||||
// Check if a custom scheme is being used, and if it exists in LSApplicationQueriesSchemes
|
||||
if (![[scheme lowercaseString] hasPrefix:@"http"] && ![[scheme lowercaseString] hasPrefix:@"https"]) {
|
||||
if (canOpen) {
|
||||
resolve(@YES);
|
||||
} else if (![[scheme lowercaseString] hasPrefix:@"http"] && ![[scheme lowercaseString] hasPrefix:@"https"]) {
|
||||
// On iOS 9 and above canOpenURL returns NO without a helpful error.
|
||||
// Check if a custom scheme is being used, and if it exists in LSApplicationQueriesSchemes
|
||||
NSArray *querySchemes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"LSApplicationQueriesSchemes"];
|
||||
if (querySchemes != nil && ([querySchemes containsObject:scheme] || [querySchemes containsObject:[scheme lowercaseString]])) {
|
||||
resolve(@(canOpen));
|
||||
resolve(@NO);
|
||||
} else {
|
||||
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@. Add %@ to LSApplicationQueriesSchemes in your Info.plist.", URL, scheme], nil);
|
||||
}
|
||||
} else {
|
||||
resolve(@(canOpen));
|
||||
resolve(@NO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user