如何在React Native应用程序中创建"评价此应用程序"链接?

vta*_*ine 29 app-store ios react-native

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

Ser*_*zN1 24

对于iOS,您必须添加LSApplicationQueriesSchemes为数组参数并向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));
}
Run Code Online (Sandbox Code Playgroud)

  • iOS模拟器也没有安装Play商店,因此在模拟器上总是会失败.您需要在真实设备上进行测试. (4认同)

out*_*ure 22

使用" 链接"打开应用商店的网址.要构建正确的URL,请按照iOS和/或android的说明进行操作.例如

Linking.openURL('market://details?id=myandroidappid')
Run Code Online (Sandbox Code Playgroud)

要么

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

  • @Gezim 将“itms://”替换为“itms-apps://” (3认同)
  • 这应该可以正常工作,但是在为 iOS 9+ 构建时,您需要添加“LSApplicationQueriesSchemes”,如下所述:http://facebook.github.io/react-native/docs/linking.html#canopenurl (2认同)
  • iOS模拟器也没有安装Play Store,所以在模拟器上总是会失败:( (2认同)

Sim*_*mar 14

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

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));
                }
            }},
        ]
    );
}
Run Code Online (Sandbox Code Playgroud)

  • mt = 8是做什么的?我想知道这是否特定于地区并必要? (5认同)
  • @AnshulKoka,mt代表"媒体类型",值8代表"移动软件应用程序".有关详细信息,请参阅/sf/ask/124699921/ (5认同)

Nab*_*l K 6

我正在使用这个。看起来不错。您只需要指定包名称和应用商店 ID 并调用该函数。而且它也是跨平台的。

render() {
        return (
            <View>
                <Button title="Rate App" onPress={()=>{
                    let options = {
                        AppleAppID:"2193813192",
                        GooglePackageName:"com.mywebsite.myapp",
                        AmazonPackageName:"com.mywebsite.myapp",
                        OtherAndroidURL:"http://www.randomappstore.com/app/47172391",
                        preferredAndroidMarket: AndroidMarket.Google,
                        preferInApp:false,
                        openAppStoreIfInAppFails:true,
                        fallbackPlatformURL:"http://www.mywebsite.com/myapp.html",
                    }
                    Rate.rate(options, (success)=>{
                        if (success) {
                            // this technically only tells us if the user successfully went to the Review Page. Whether they actually did anything, we do not know.
                            this.setState({rated:true})
                        }
                    })
                } />
            </View>
        )
    }
Run Code Online (Sandbox Code Playgroud)


rob*_*e_c 5

2021 年更新:

SKStoreReviewController其他一些答案相当旧,并且不支持使用 iOS 10.3 ( ) 和 Android 5 ( )中添加的应用内审核 API ReviewManager。如果您要在 2021 年向 React Native 应用程序添加评论,则最好使用这些评论(如果可用)。

Expo 提供了一个库https://docs.expo.io/versions/latest/sdk/storereview/,如果用户设备支持这些较新的 API,它将使用这些 API,如果不支持,则退回到打开商店页面。

还有https://github.com/KjellConnelly/react-native-rate具有类似的功能,但有更多的配置选项。例如,您可以决定是否部分或全部使用应用内 API(这可能是个好主意,因为应用内 API 对用户来说摩擦要小得多,但您只能询问几次一年)。