相关博文:H5页面在浏览器中跳转APP的方式/URL Scheme/Universal Link
相关版本:
? “react-native”: “0.61.5”
Android原生
在AndroidManifest.xml 中添加如下代码,如果已经存在了MainActivity 就在里面添加。
<activity
android:name="com.xxx.MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="name" /> // 唤醒的路径,例如name://
</intent-filter>
</activity>
React Native
-
在App.js 配置未打开App时的第一次唤醒。 Linking.getInitialURL() 拿到唤醒的url,如果没有返回空。 import { Linking } from "react-native";
componentDidMount() {
Linking.getInitialURL()
.then(url => {
if (url) {
this.handleDeepLinking({ url }); // 一些需要的操作
}
})
}
-
在需要对唤醒做出响应的页面进行监听,一般在App.js 。 componentDidMount() {
Linking.addEventListener('url', this.handleDeepLinking);
}
componentWillUnmount() {
Linking.removeEventListener('url');
}
|