问题
我正在尝试设置深度链接,但它不会打开URL中指定的正确屏幕。应用程序会打开,但总是打开当前屏幕而不是在URL中指定的屏幕。
我的应用程序具有以下导航结构,并且当应用程序打开时我正在尝试导航到通知屏幕
- 顶级Switch Navigator
- SplashScreen
- AuthLoading Screen
- App (底部TabNavigator)
- Home
- Profile
- Notifications
- Auth
我尝试过的事情
我已经尝试建立一个新应用程序并遵循他们的文档,在新项目中它可以正常工作,但我无法让它在当前项目中工作。我还在新项目中包含了redux以测试相同的环境。
我通过运行xcrun simctl openurl booted esportsdeeplink://app/notifications
来进行测试 iOS,和 adb shell am start -W -a android.intent.action.VIEW -d “esportsdeeplink://app/notifications” com.benji.esportscompetition
用于 android。
两者都有相同的结果,打开应用程序但不导航到指定页面
环境
- react-native v0.60.4
- react-navigation v3.11.1
- redux v4.0.4
- react-redux v7.1.0
代码 我尝试包括所有相关代码,但削减了一些导入和其他代码,以尝试简明扼要。如果您发现它有帮助,我可以发布任何其他代码
Index.js(入口点)
import App from './src/app/App';
const ReactNativeRedux = () => (
<Provider store={store}>
<PersistGate loading={<SplashScreen />} persistor={persistor}>
<PushNotifications />
<App />
</PersistGate>
</Provider>
);
AppRegistry.registerComponent(appName, () => ReactNativeRedux);
App.js
import AppContainer from './Components/BottomNavigation/NavigationRouting';
class App extends React.Component {
render(props) {
const prefix = 'esportsdeeplink://'
console.log('prefix', prefix)
return (
<Fragment>
<View style={{ flex: 1, backgroundColor }}>
<StatusBar translucent backgroundColor="transparent" />
<LoadingSpinner loading={this.props.loading} />
<AppContainer
ref={(navigatorRef) => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
uriPrefix={prefix}
screenProps={{
http,
saveFriendsFnUser: this.saveFriendsFnUser,
signupComplete: this.signupComplete,
}}
/>
</View>
</Fragment>
);
}
}
const mapStateToProps = (state) => ({
loading: state.api.loading,
user: state.user,
math: state.math,
response: state.response,
});
const mapDispatchToProps = (dispatch) => ({
startupRequest: () => {
dispatch(startupRequest());
},
});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(App);
导航路由(NavigationRouting.js,我的导航器创建的地方)
const BottomTabNav = createBottomTabNavigator(
{
Home: {
screen: HomeScreen
},
Profile: {
screen: ProfileStack
},
Notifications: {
screen: Notifications,
navigationOptions: () => ({
tabBarVisible: false
}),
path: 'notifications',
},
},
{
tabBarComponent: CustomTabNav,
initialRouteName: "Home"
}
);
export default createAppContainer(
createSwitchNavigator(
{
SplashScreen,
AuthLoading: AuthLoadingScreen,
App: {
screen: BottomTabNav,
path: 'app',
},
Auth: {
screen: AuthStack,
path: 'auth'
}
}
)
);
深度链接设置
iOS
projectFolder/ios/eSportsCompetition/AppDelegate.m
#import <React/RCTLinkingManager.h>
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
@end
安卓
项目文件夹/android/app/src/main/AndroidManifest.xml
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
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="esportsdeeplink" />
</intent-filter>
</activity>