小编zah*_*hay的帖子

用于后台应用程序的 useURL hook expo-linking

React Native包expo-linking有一个名为 的钩子,useURL当应用程序在后台运行时,该钩子对我不起作用。从文档来看,Returns the initial URL followed by any subsequent changes to the URL.我的托管博览会应用程序遇到的问题是,当应用程序已在后台打开时,挂钩不起作用。这是钩子:

export default function App() {
  const isLoadingComplete = useCachedResources();
  const url = Linking.useURL();

  useEffect(() => {
    Alert.alert(url ? url.substring(20) : 'null');
  }, [url]);

  if (!isLoadingComplete) {
    return null;
  } else {
    return (
      ...
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

exp://exp.host/@myprofile/myproject?a=b如果我在应用程序关闭时打开 URL ,我会按预期收到警报。如果应用程序在后台运行,则警报不会响起。我已经在 iOS 模拟器和物理 Android 上进行了测试。有什么解决办法吗?请注意,类似的问题也发生在Linking.addEventListener().

react-native expo react-native-deep-linking expo-linking

5
推荐指数
1
解决办法
1445
查看次数