【问题标题】:URL scheme is working correctly for ios but not for android in react nativeURL 方案在 ios 上正常工作,但在原生反应中不适用于 android
【发布时间】:2020-08-23 04:37:27
【问题描述】:

我已经尝试了几乎所有的解决方案和变体来完成这项工作。可能是我遗漏了一些微不足道的东西,但我无法弄清楚。

以下是我的 AndroidManifest.xml 的代码

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  package="com.linkup">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:usesCleartextTraffic="true"
      tools:targetApi="28"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustPan"
        android:launchMode="singleTask">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
        </intent-filter>
        <intent-filter android:label="filter_react_native">
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:scheme="linkupcaribbean" android:host="paymentsuccess" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />   
    </application>

</manifest>

我也尝试过从浏览器和应用程序打开“intent://paymentsuccess/#Intent;scheme=linkupcaribbean;package=com.linkup;end”,如https://developer.chrome.com/multidevice/android/intents 中所述,但这似乎也不起作用。

也试过这个Deep linking react native app on Android 和其他类似的。

我从 App.js 返回以下代码

return (
    <Provider store={store}>
      {/* {currLang = useSelector((state) => state.language.language)}
      {strings.setLanguage(currLang)} */}
      <PersistGate persistor={persistor}>
        <AppNavigator uriPrefix={'linkupcaribbean://'} />
      </PersistGate>
    </Provider>
  )

在我的导航器中

const AppNavigator = createStackNavigator(
    {
        Tabs: ShopBottomNavigator,
        SearchLocation: SearchLocationScreen,
        SearchByWords: SearchByWordsScreen,
        Discover: DiscoverScreen,
        DiscoverSubCategory: DiscoverSubCategoryScreen,
        ShowAllBusiness: ShowAllBusinessScreen,
        ShowAllBusinessWithFilters: ShowAllBusinessWithFiltersScreen,
        BusinessDetail: BusinessDetailStack,
        ShowAllEvents: ShowAllEventsScreen,
        ShowAllFavouriteEvents: ShowAllFavouriteEventsScreen,
        Filters: FiltersScreen,
        AddBusiness: AddBusinessScreen,
        ManagePayments: ManagePaymentsScreen,
        ShowAllProducts: ShowAllProductsScreen,
        ShowAllFavouriteProducts: ShowAllFavouriteProductsScreen,
        EventDetail: EventDetailStack,
        Notifications: NotificationsScreen,
        ShowAllDeals: ShowAllDealsScreen,
        ProductDetail: ProductDetailStack,
        MyCart: MyCartScreen,
        OrderDetail: OrderDetailScreen,
        EditProfile: MyProfileScreen,
        MyWallet: MyWalletScreen,
        ManageCard: ManageCardScreen,
        ShippingAddress: ShippingAddressScreen,
        PrivacyPolicy: PrivacyPolicyScreen,
        TermsAndConditions: TermsAndConditionsScreen,
        AboutApp: AboutAppScreen,
        GetHelp: GetHelpScreen,
        ChangePassword: ChangePasswordScreen,
        AddEditAddress: AddEditAddressScreen,
        AddReview: AddReviewScreen,
        Checkout: CheckoutScreen,
        AddNewCard: AddNewCardScreen,
        AllReviews: AllReviewsScreen,
        ShowReview: ShowReviewScreen,
        DealDetail: DealDetailScreen,
        PromotionDetail: PromotionDetailScreen,
        BuyerManagePayment: BuyerManagePaymentScreen,
        FilterEventScreen: FilterEventScreen,
        FilterProductScreen: FilterProductScreen,
        PaymentSuccess: {
            screen: PaymentSuccessScreen,
            path: 'paymentsuccess'
        }
    },
    {
        defaultNavigationOptions: {
            header: null,
        }
    }
);

我正在使用 react-navigation 4

【问题讨论】:

    标签: android react-native deep-linking url-scheme


    【解决方案1】:

    根据您的要求更改此设置

    export const RootNavigator = () => {
      const deepLinking = {
        prefixes: ['https://www.example.com'],
        config: {
          AuthNavigator: {
            initialRouteName: 'Registration',
            screens: {
              Login: {
                path: 'Login/:token',
                params: {
                  token: '',
                },
              },
            },
          },
        },
      };
      return (
        <NavigationContainer linking={deepLinking}>
          <Stack.Navigator screenOptions={{headerShown: false}}>
            <Stack.Screen name="Splash" component={Splash} />
            <Stack.Screen name="AuthNavigator" component={AuthNavigator} />
            <Stack.Screen name="MainNavigator" component={MainNavigator} />
          </Stack.Navigator>
        </NavigationContainer>
      );
    };
    

    这是我的 authNavigator,以防你需要它

    export const AuthNavigator = () => {
      return (
        <Stack.Navigator
          screenOptions={{
            headerShown: true,
            header: ({navigation}) => (
              <Header onBackPress={() => navigation.goBack()} />
            ),
          }}>
          <Stack.Screen
            name="OnBoarding"
            component={OnBoarding}
            options={{headerShown: false}}
          />
          <Stack.Screen
            name="Registration"
            component={Registration}
            options={{headerShown: false}}
          />
          <Stack.Screen name="Registration1" component={Registration1} />
          <Stack.Screen name="Login" component={Login} />
          <Stack.Screen name="ForgotPassword" component={ForgotPassword} />
          <Stack.Screen name="LocationAccess" component={LocationAccess} />
          <Stack.Screen name="AddressDetails" component={AddressDetails} />
        </Stack.Navigator>
      );
    };
    

    并在 android manifest 中的现有意图过滤器下方添加此意图过滤器

    <intent-filter android:label="@string/app_name">
                  <action android:name="android.intent.action.VIEW" />
                  <category android:name="android.intent.category.DEFAULT" />
                  <category android:name="android.intent.category.BROWSABLE" />
                 <data android:scheme="https"
                  android:host="www.example.com"
                  android:pathPrefix="/Login" />
              </intent-filter>  
    

    【讨论】:

    • 你能把它改成 react-navigation 4 吗?
    猜你喜欢
    • 2021-06-13
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    • 2014-04-09
    • 2016-03-04
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多