通过 yourapp://test?a=1&n=2 链接来打开app后获取参数

 Linking.getInitialURL().then(async url => {
      console.warn('启动唤醒:', url)
    });

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

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

 
              
              
              
              
          

iOS需要这样子配置:

- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary *)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);

你可能感兴趣的:(通过 yourapp://test?a=1&n=2 链接来打开app后获取参数)