通过 yourapp://test?a=1&n=2 链接来打开a

2022-08-31  本文已影响0人  sunny635533
 Linking.getInitialURL().then(async url => {
      console.warn('启动唤醒:', url)
    });

    Linking.addEventListener('url', event => {
      console.warn('后台唤醒:', event.url)
    })

android和ios都可以通过这个来获取打开app时的参数,
Android还需要这样子配置,在某个activity下添加:

 <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="yourappScheme" />
          </intent-filter>

iOS需要这样子配置:

- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
   return [RCTLinkingManager application:application openURL:url options:options];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{

   return [RCTLinkingManager application:application openURL:url
                                sourceApplication:sourceApplication annotation:annotation];
}

iOS可以通过safari网页上输入:yourapp://test?a=1&n=2,直接跳转到app,并获取到参数;
Android的话可以通过其他app调起:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("yourAppScheme://?id=100"));
startActivity(intent);

上一篇下一篇

猜你喜欢

热点阅读