如何在React Native应用程序中制作“评价此应用程序”链接?

如何在iOS上的React Native应用程序中将用户正确链接到App Store应用程序的评论页面?

对于iOS,您必须将LSApplicationQueriesSchemes作为Array参数添加到Info.plist并向其添加项目。

例如,对于AppStore链接,我使用itms-apps作为此数组中的params之一。

你的链接应该是这样的

itms-apps://itunes.apple.com/us/app/id${APP_STORE_LINK_ID}?mt=8

好。 现在你有了使用方法做Link组件的所有东西

 handleClick () { Linking.canOpenURL(link).then(supported => { supported && Linking.openURL(link); }, (err) => console.log(err)); } 

使用“ 链接”打开app store的url。 要构建正确的URL,请按照iOS和/或android的说明进行操作。 例如

 Linking.openURL('market://details?id=myandroidappid') 

要么

 Linking.openURL('itms://itunes.apple.com/us/app/apple-store/myiosappid?mt=8') 

这是类似的,它显示了一个警告框来更新应用程序,它会打开游戏商店或应用程序商店,具体取决于他们的设备操作系统。

 function updateAppNotice(){ const APP_STORE_LINK = 'itms://itunes.apple.com/us/app/apple-store/myiosappid?mt=8'; const PLAY_STORE_LINK = 'market://details?id=myandroidappid'; Alert.alert( 'Update Available', 'This version of the app is outdated. Please update app from the '+(Platform.OS =='ios' ? 'app store' : 'play store')+'.', [ {text: 'Update Now', onPress: () => { if(Platform.OS =='ios'){ Linking.openURL(APP_STORE_LINK).catch(err => console.error('An error occurred', err)); } else{ Linking.openURL(PLAY_STORE_LINK).catch(err => console.error('An error occurred', err)); } }}, ] ); } 

我正在使用这个库 。 看起来很不错。 您只需指定包名称和App Store ID并调用该函数即可。 它也是跨平台的。

 render() { return (   ) }