From af949877e67c9ff56089436c7980037a9e332c7c Mon Sep 17 00:00:00 2001 From: Johan Date: Tue, 16 May 2017 17:51:20 -0700 Subject: [PATCH] updated docs with iOS 10 compatible linking code Summary: Thanks for submitting a PR! Please read these instructions carefully: - [x] Explain the **motivation** for making this change. - [x] Provide a **test plan** demonstrating that the code is solid. - [x] Match the **code formatting** of the rest of the codebase. - [x] Target the `master` branch, NOT a "stable" branch. The current code for IOS contains deprecated code for incoming urls. in iOS 10 deprecated openURL. more details here: https://useyourloaf.com/blog/openurl-deprecated-in-ios10/ 1. Create an RN app with iOS 10. set up linking as per instructions. 2. Using the iOS9 code snippet, with the app is open, navigate to the apps url scheme (in safari) appname://value1/value2, the eventListener will not trigger. note: it will however trigger getInitialURL if app is closed. 3. Replace the old iOS9 code with the iOS 10 and trigger an incoming url from a browser appname:// with the new code in the doc it will trigger for both open and closed apps. Closes https://github.com/facebook/react-native/pull/13942 Differential Revision: D5071851 Pulled By: hramos fbshipit-source-id: 8394de73014a1d2a5982b22b1b6fd09e0cf524dd --- Libraries/Linking/Linking.js | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Libraries/Linking/Linking.js b/Libraries/Linking/Linking.js index 32b5a0298..4962aae04 100644 --- a/Libraries/Linking/Linking.js +++ b/Libraries/Linking/Linking.js @@ -66,22 +66,44 @@ const LinkingManager = Platform.OS === 'android' ? * android:launchMode="singleTask"> * ``` * - * NOTE: On iOS you'll need to link `RCTLinking` to your project by following + * NOTE: On iOS, you'll need to link `RCTLinking` to your project by following * the steps described [here](docs/linking-libraries-ios.html#manual-linking). - * In case you also want to listen to incoming app links during your app's - * execution you'll need to add the following lines to your `*AppDelegate.m`: + * If you also want to listen to incoming app links during your app's + * execution, you'll need to add the following lines to your `*AppDelegate.m`: * * ``` + * // iOS 10 + * #import + * - (BOOL)application:(UIApplication *)application + * openURL:(NSURL *)url + * options:(NSDictionary *)options + * { + * + * return [RCTLinkingManager application:application openURL:url + * sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] + * annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]; + * + * } + * ``` + * + * If you're targeting iOS 9 or older, you can use the following code instead: + * + * ``` + * // iOS 9 or older * #import * * - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url * sourceApplication:(NSString *)sourceApplication annotation:(id)annotation * { * return [RCTLinkingManager application:application openURL:url - * sourceApplication:sourceApplication annotation:annotation]; + * 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). + * ``` + * + * If your app is using [Universal Links](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html), + * you'll need to add the following code as well: + * + * ``` * - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity * restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler * {