Add support for Universal Links

Summary:
Adds support for [Universal Links](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html).
Closes https://github.com/facebook/react-native/pull/4109

Reviewed By: svcscm

Differential Revision: D2658105

Pulled By: nicklockwood

fb-gh-sync-id: 7d94564f64cda7d31c79cf8f4c450ed2387057be
This commit is contained in:
SangYeob Bono Yu 2015-12-04 08:05:11 -08:00 коммит произвёл facebook-github-bot-7
Родитель c71811e491
Коммит f4c286f7ac
3 изменённых файлов: 37 добавлений и 5 удалений

Просмотреть файл

@ -43,9 +43,22 @@ var DEVICE_NOTIF_EVENT = 'openURL';
* execution you'll need to add the following lines to you `*AppDelegate.m`:
*
* ```
* - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
* return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
* - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
* sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
* {
* return [RCTLinkingManager application:application openURL:url
* sourceApplication:sourceApplication annotation:annotation];
* }
*
* // Only if your app is using [Universal Links](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html).
* - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
* restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
* {
* return [RCTLinkingManager application:application
* continueUserActivity:userActivity
* restorationHandler:restorationHandler];
* }
*
* ```
*
* And then on your React component you'll be able to listen to the events on
@ -71,7 +84,7 @@ var DEVICE_NOTIF_EVENT = 'openURL';
* LinkingIOS.openURL(url)
* ```
*
* If you want to check if any installed app can handle a given URL beforehand you can call
* If you want to check if any installed app can handle a given URL beforehand, call
* ```
* LinkingIOS.canOpenURL(url, (supported) => {
* if (!supported) {
@ -130,7 +143,7 @@ class LinkingIOS {
* Determine whether or not an installed app can handle a given URL.
* The callback function will be called with `bool supported` as the only argument
*
* NOTE: As of iOS 9, your app needs to provide a `LSApplicationQueriesSchemes` key
* NOTE: As of iOS 9, your app needs to provide the `LSApplicationQueriesSchemes` key
* inside `Info.plist`.
*/
static canOpenURL(url: string, callback: Function) {

Просмотреть файл

@ -18,4 +18,8 @@
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation;
+ (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler;
@end

Просмотреть файл

@ -54,6 +54,19 @@ RCT_EXPORT_MODULE()
return YES;
}
+ (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler
{
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
NSDictionary *payload = @{@"url": userActivity.webpageURL.absoluteString};
[[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification
object:self
userInfo:payload];
}
return YES;
}
- (void)handleOpenURLNotification:(NSNotification *)notification
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"openURL"
@ -62,6 +75,7 @@ RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(openURL:(NSURL *)URL)
{
// TODO: we should really return success/failure via a callback here
// Doesn't really matter what thread we call this on since it exits the app
[RCTSharedApplication() openURL:URL];
}
@ -72,7 +86,8 @@ RCT_EXPORT_METHOD(canOpenURL:(NSURL *)URL
if (RCTRunningInAppExtension()) {
// Technically Today widgets can open urls, but supporting that would require
// a reference to the NSExtensionContext
callback(@[@(NO)]);
callback(@[@NO]);
return;
}
// This can be expensive, so we deliberately don't call on main thread