React native Linking to another app

て烟熏妆下的殇ゞ 提交于 2019-11-29 02:05:42

You do not need to npm install link --save or to use the "Linking Libraries in iOS" guide. The "<Linking /> component" and the "Linking librairies action" are two very different things.

<Linking /> is a component that allows you to open links (web urls, or links to other apps) and to detect when your app is called from a link (from a browser or another app, or a push notification for example). It is a core component of React Native and comes with the react-native npm package.

Linking librairies is necessary when you install a third party library (like react-native-maps for example) and you need to add the dependencies to your iOS Xcode and Android Gradle build configurations. It is usually done with the react-native link <package> command, after you npm install it.

The only thing you must do is require or import <Linking /> in your javascript file before using it. You do not even need the whole part about Handling deep links from the documentation. That is only for incoming links that open your app. All you need starts at Opening external links

Now, why your code fails is a mystery. Here is a link to a working app that has the exact same behavior. A concise example would be:

import React from 'react';
import { TouchableOpacity, Linking, Text } from 'react-native';

export default function Button() {
  return (
    <TouchableOpacity onPress={() => Linking.openURL('https://maps.google.com?q=stack+overflow+offices')}>
      <Text>Press me</Text>
    </TouchableOpacity>
  );
}

You can also test it here on rnplay.

I suggest cleaning your project, removing the node_modules folder and doing npm install again, and compiling your project new.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!