【问题标题】:How to make a "Rate this app" link in React Native app?如何在 React Native 应用程序中创建“评价此应用程序”链接?
【发布时间】:2016-06-07 08:19:21
【问题描述】:

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

【问题讨论】:

    标签: ios app-store react-native


    【解决方案1】:

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

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

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

    【讨论】:

    • 这应该可以正常工作,但是在为 iOS 9+ 构建时,您需要添加 LSApplicationQueriesSchemes,如下所述:facebook.github.io/react-native/docs/linking.html#canopenurl
    • iOS模拟器也没有安装Play Store,所以在模拟器上总是会失败:(
    • 更多信息可以在这里找到johnsonsu.com/…
    • 这对于 iOS 来说已经过时了。它会尝试打开 iTunes Store 而不是 App Store。
    • @Gezim 将 itms:// 替换为 itms-apps://
    【解决方案2】:

    这是类似的,它显示一个更新应用程序的警告框,并根据他们的设备操作系统打开 Play 商店或应用商店。

    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));
                    }
                }},
            ]
        );
    }
    

    【讨论】:

    • mt=8 是做什么的?我想知道这是否是特定地区的和必要的?
    • @AnshulKoka,mt 代表“媒体类型”,值 8 对应于“移动软件应用程序”。欲了解更多信息,请参阅stackoverflow.com/questions/1781427/…
    【解决方案3】:

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

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

    例如:

    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>itms-apps</string>
    </array>
    

    你的链接应该是这样的

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

    嗯。现在你可以用方法来做链接组件了

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

    【讨论】:

    • 请注意,LSApplicationQueriesSchemes 仅在为 iOS 9+ 构建时才需要:facebook.github.io/react-native/docs/linking.html#canopenurl
    • iOS 模拟器也没有安装 Play 商店,所以在模拟器上总是会失败。您需要在真机上进行测试。
    • 如何像这样添加LSApplicationQueriesSchemesLSApplicationQueriesSchemes or..??
    • developer.apple.com/library/archive/documentation/General/… 开始,LSApplicationQueriesSchemes 键的值是一个包含您要支持的 URL 的数组。
    • @HoàngVũAnh &lt;key&gt;LSApplicationQueriesSchemes&lt;/key&gt; &lt;array&gt; &lt;string&gt;itms-apps&lt;/string&gt; &lt;/array&gt;
    【解决方案4】:

    我正在使用这个library。似乎还不错。您只需要指定包名称和应用商店 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>
            )
        }
    

    【讨论】:

      【解决方案5】:

      使用第三方库,在ios中是打开itunes,我告诉你打开appstore的具体方法。 首先你应该是活的,它会在物理设备上工作(不保证模拟器)

      const url = Platform.OS === 'android' ?
                          'https://play.google.com/store/apps/details?id=YOUR_APP_ID'   :  'https://apps.apple.com/us/app/doorhub-driver/id_YOUR_APP_ID'
                      Linking.openURL(url)
      

      您可以通过在 appstore 上搜索您的应用并复制该网址来找到您的 ios 链接。

      【讨论】:

        【解决方案6】:

        2021 年更新:

        其他一些答案相当陈旧,不支持使用 iOS 10.3 (SKStoreReviewController) 和 Android 5 (ReviewManager) 中添加的应用内评论 API。如果您在 2021 年为您的 React Native 应用添加评论,那么您最好使用这些评论(如果可用)。

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

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

        【讨论】:

          猜你喜欢
          • 2013-04-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-02-01
          相关资源
          最近更新 更多