如果应用程序关闭,则反应导航深度链接不起作用

2024-01-04

当应用程序打开时,深度链接工作得很好,但当关闭时,它只打开我的应用程序。

当我检查警报时,我想要的数据到达 getInitialUrl 部分,但没有数据到达订阅。最后的办法就是在这里发帖,我真的不明白。您的帮助对我来说非常重要!

/**
Main.Activity.java
public class MainActivity extends ReactActivity {

  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(null);
   }
   @Override
    protected ReactActivityDelegate createReactActivityDelegate() {
      return new ReactActivityDelegate(this, getMainComponentName()) {
        @Override
        protected ReactRootView createRootView() {
        return new RNGestureHandlerEnabledRootView(MainActivity.this);
        }
      };
  }
}
**/

导航

<NavigationContainer
                    theme={theme === 'dark' ? DarkTheme : DefaultTheme}
                    ref={navigationRef}
                    initialRouteName="App"
                    linking={{
                        prefixes: ["https://*****", "*****://"],
                        config,
                        async getInitialURL() {
                            // Check if app was opened from a deep link
                            const url = await Linking.getInitialURL();

                            if (url != null) {
                                return url;
                            }

                            // Check if there is an initial firebase notification
                            const message = await messaging().getInitialNotification();

                            // Get the `url` property from the notification which corresponds to a screen
                            // This property needs to be set on the notification payload when sending it
                            return message?.notification.url;
                        },
                        subscribe(listener) {
                            const onReceiveURL = ({ url }: { url: string }) => listener(url);

                            // Listen to incoming links from deep linking
                            Linking.addEventListener('url', onReceiveURL);

                            // Listen to firebase push notifications
                            const unsubscribeNotification = messaging().onNotificationOpenedApp(
                                (message) => {
                                    const url = message.notification.url;

                                    if (url) {
                                        // Any custom logic to check whether the URL needs to be handled
                                        //...

                                        // Call the listener to let React Navigation handle the URL
                                        listener(url);
                                    }
                                }
                            );

                            return () => {
                                // Clean up the event listeners
                                Linking.removeEventListener('url', onReceiveURL);
                                unsubscribeNotification();
                            };
                        },
                    }}
                >

AndroidManifest.xml

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.vis.smartiq">
        <queries>
          <package android:name="com.google.android.googlequicksearchbox"/>
        </queries>
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.RECORD_AUDIO" />
        <application
          android:name=".MainApplication"
          android:label="@string/app_name"
          android:icon="@mipmap/ic_launcher"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:allowBackup="false"
          android:theme="@style/AppTheme">
          <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
            android:launchMode="singleTask"
            android:windowSoftInputMode="adjustResize"
            android:exported="true">
            <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="smartiq" />
                <data android:scheme="https" android:host="login.smartiq.io" />
            </intent-filter>
          </activity>
        </application>
    </manifest>

构建.gradle

  // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        ext {
            buildToolsVersion = "30.0.2"
            minSdkVersion = 23
            compileSdkVersion = 31
            targetSdkVersion = 31
            ndkVersion = "21.4.7075529"
        }
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath('com.android.tools.build:gradle:7.0.0')
            classpath 'com.google.gms:google-services:4.3.10'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            mavenCentral()
            mavenLocal()
            maven {
                // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                url("$rootDir/../node_modules/react-native/android")
            }
            maven {
                // Android JSC is installed from npm
                url("$rootDir/../node_modules/jsc-android/dist")
            }
    
            google()
            maven { url 'https://www.jitpack.io' }
        }
    }

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如果应用程序关闭,则反应导航深度链接不起作用 的相关文章

随机推荐