mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Updated docs for next
This commit is contained in:
@@ -7,7 +7,12 @@ access and handle it from any component you want with</p><div class="prism langu
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token keyword">catch</span><span class="token punctuation">(</span>err <span class="token operator">=</span><span class="token operator">></span> console<span class="token punctuation">.</span><span class="token function">error<span class="token punctuation">(</span></span><span class="token string">'An error occurred'</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<span class="token punctuation">}</span></div><p>NOTE: For instructions on how to add support for deep linking on Android,
|
||||
refer to <a href="http://developer.android.com/training/app-indexing/deep-linking.html#adding-filters" target="_blank">Enabling Deep Links for App Content - Add Intent Filters for Your Deep Links</a>.</p><p>NOTE: On iOS you'll need to link <code>RCTLinking</code> to your project by following
|
||||
refer to <a href="http://developer.android.com/training/app-indexing/deep-linking.html#adding-filters" target="_blank">Enabling Deep Links for App Content - Add Intent Filters for Your Deep Links</a>.</p><p>If you wish to receive the intent in an existing instance of MainActivity,
|
||||
you may set the <code>launchMode</code> of MainActivity to <code>singleTask</code> in
|
||||
<code>AndroidManifest.xml</code>. See <a href="http://developer.android.com/guide/topics/manifest/activity-element.html" target="_blank"><code><activity></code></a>
|
||||
documentation for more information.</p><div class="prism language-javascript"><activity
|
||||
android<span class="token punctuation">:</span>name<span class="token operator">=</span><span class="token string">".MainActivity"</span>
|
||||
android<span class="token punctuation">:</span>launchMode<span class="token operator">=</span><span class="token string">"singleTask"</span><span class="token operator">></span></div><p>NOTE: On iOS you'll need to link <code>RCTLinking</code> to your project by following
|
||||
the steps described <a href="docs/linking-libraries-ios.html#manual-linking" target="_blank">here</a>.
|
||||
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 you <code>*AppDelegate.m</code>:</p><div class="prism language-javascript">#import <span class="token string">"RCTLinkingManager.h"</span>
|
||||
@@ -35,14 +40,14 @@ execution you'll need to add the following lines to you <code>*AppDelegate.
|
||||
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
||||
<span class="token function">_handleOpenURL<span class="token punctuation">(</span></span>event<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||||
console<span class="token punctuation">.</span><span class="token function">log<span class="token punctuation">(</span></span>event<span class="token punctuation">.</span>url<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<span class="token punctuation">}</span></div><p>Note that this is only supported on iOS.</p><h4><a class="anchor" name="opening-external-links"></a>Opening external links <a class="hash-link" href="docs/linking.html#opening-external-links">#</a></h4><p>To start the corresponding activity for a link (web URL, email, contact etc.), call</p><div class="prism language-javascript">Linking<span class="token punctuation">.</span><span class="token function">openURL<span class="token punctuation">(</span></span>url<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token keyword">catch</span><span class="token punctuation">(</span>err <span class="token operator">=</span><span class="token operator">></span> console<span class="token punctuation">.</span><span class="token function">error<span class="token punctuation">(</span></span><span class="token string">'An error occurred'</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></div><p>If you want to check if any installed app can handle a given URL beforehand you can call</p><div class="prism language-javascript">Linking<span class="token punctuation">.</span><span class="token function">canOpenURL<span class="token punctuation">(</span></span>url<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then<span class="token punctuation">(</span></span>supported <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span>
|
||||
<span class="token punctuation">}</span></div><h4><a class="anchor" name="opening-external-links"></a>Opening external links <a class="hash-link" href="docs/linking.html#opening-external-links">#</a></h4><p>To start the corresponding activity for a link (web URL, email, contact etc.), call</p><div class="prism language-javascript">Linking<span class="token punctuation">.</span><span class="token function">openURL<span class="token punctuation">(</span></span>url<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token keyword">catch</span><span class="token punctuation">(</span>err <span class="token operator">=</span><span class="token operator">></span> console<span class="token punctuation">.</span><span class="token function">error<span class="token punctuation">(</span></span><span class="token string">'An error occurred'</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></div><p>If you want to check if any installed app can handle a given URL beforehand you can call</p><div class="prism language-javascript">Linking<span class="token punctuation">.</span><span class="token function">canOpenURL<span class="token punctuation">(</span></span>url<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then<span class="token punctuation">(</span></span>supported <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>supported<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||||
console<span class="token punctuation">.</span><span class="token function">log<span class="token punctuation">(</span></span><span class="token string">'Can\'t handle url: '</span> <span class="token operator">+</span> url<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">return</span> Linking<span class="token punctuation">.</span><span class="token function">openURL<span class="token punctuation">(</span></span>url<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token keyword">catch</span><span class="token punctuation">(</span>err <span class="token operator">=</span><span class="token operator">></span> console<span class="token punctuation">.</span><span class="token function">error<span class="token punctuation">(</span></span><span class="token string">'An error occurred'</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></div></div><span><h3><a class="anchor" name="methods"></a>Methods <a class="hash-link" href="docs/linking.html#methods">#</a></h3><div class="props"><div class="prop"><h4 class="propTitle"><a class="anchor" name="constructor"></a>constructor<span class="propType">()</span> <a class="hash-link" href="docs/linking.html#constructor">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="addeventlistener"></a>addEventListener<span class="propType">(type, handler)</span> <a class="hash-link" href="docs/linking.html#addeventlistener">#</a></h4><div><p>Add a handler to Linking changes by listening to the <code>url</code> event type
|
||||
and providing the handler</p><p>@platform ios</p></div></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="removeeventlistener"></a>removeEventListener<span class="propType">(type, handler)</span> <a class="hash-link" href="docs/linking.html#removeeventlistener">#</a></h4><div><p>Remove a handler by passing the <code>url</code> event type and the handler</p><p>@platform ios</p></div></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="openurl"></a>openURL<span class="propType">(url)</span> <a class="hash-link" href="docs/linking.html#openurl">#</a></h4><div><p>Try to open the given <code>url</code> with any of the installed apps.</p><p>You can use other URLs, like a location (e.g. "geo:37.484847,-122.148386"), a contact,
|
||||
and providing the handler</p></div></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="removeeventlistener"></a>removeEventListener<span class="propType">(type, handler)</span> <a class="hash-link" href="docs/linking.html#removeeventlistener">#</a></h4><div><p>Remove a handler by passing the <code>url</code> event type and the handler</p></div></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="openurl"></a>openURL<span class="propType">(url)</span> <a class="hash-link" href="docs/linking.html#openurl">#</a></h4><div><p>Try to open the given <code>url</code> with any of the installed apps.</p><p>You can use other URLs, like a location (e.g. "geo:37.484847,-122.148386"), a contact,
|
||||
or any other URL that can be opened with the installed apps.</p><p>NOTE: This method will fail if the system doesn't know how to open the specified URL.
|
||||
If you're passing in a non-http(s) URL, it's best to check {@code canOpenURL} first.</p><p>NOTE: For web URLs, the protocol ("http://", "https://") must be set accordingly!</p></div></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="canopenurl"></a>canOpenURL<span class="propType">(url)</span> <a class="hash-link" href="docs/linking.html#canopenurl">#</a></h4><div><p>Determine whether or not an installed app can handle a given URL.</p><p>NOTE: For web URLs, the protocol ("http://", "https://") must be set accordingly!</p><p>NOTE: As of iOS 9, your app needs to provide the <code>LSApplicationQueriesSchemes</code> key
|
||||
inside <code>Info.plist</code> or canOpenURL will always return false.</p><p>@param URL the URL to open</p></div></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="getinitialurl"></a>getInitialURL<span class="propType">()</span> <a class="hash-link" href="docs/linking.html#getinitialurl">#</a></h4><div><p>If the app launch was triggered by an app link,
|
||||
|
||||
Reference in New Issue
Block a user