Reference version

This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 55).

Expo 商店评价 iconExpo 商店评价

一个提供访问应用内评价原生 API 的库。

Android
iOS
Included in Expo Go

For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.

expo-store-review 是一个库,它提供了对 Android 5+ 上的 ReviewManager API 和 iOS 上的 SKStoreReviewController API 的访问。它允许你在不离开应用本身的情况下请求用户为你的应用评分。

安装

Terminal
npx expo install expo-store-review

If you are installing this in an existing React Native app, make sure to install expo in your project.

使用

在使用此 API 时,重要的是你要遵循 iOS 的 人机界面指南 和 Android 的 指南

具体来说:

  • 不要从按钮中调用 StoreReview.requestReview() —— 而应尝试在用户完成应用中的某个标志性交互后调用它。
  • 不要刷屏式地打扰用户。
  • 当用户正在进行需要及时完成的操作时,例如导航时,不要请求评价。
  • 在展示评分按钮或卡片之前或期间,不要向用户提任何问题。

写评价

Android

Android 上没有对应的重定向,不过你仍然可以使用查询参数 showAllReviews=true 以如下方式在 Play 商店中打开评价页面:

Android Play Store example
const androidPackageName = 'host.exp.exponent'; // 在浏览器中打开 Android Play 商店 -> 在 Android 上重定向到 Play 商店 Linking.openURL( `https://play.google.com/store/apps/details?id=${androidPackageName}&showAllReviews=true` ); // 直接打开 Android Play 商店 Linking.openURL(`market://details?id=${androidPackageName}&showAllReviews=true`);

iOS

你可以通过使用查询参数 action=write-review 将应用用户重定向到 iOS App Store 中某个应用的 “写评价” 页面。例如:

iOS App Store example
const itunesItemId = 982107779; // 在浏览器中打开 iOS App Store -> 在 iOS 上重定向到 App Store Linking.openURL(`https://apps.apple.com/app/apple-store/id${itunesItemId}?action=write-review`); // 直接打开 iOS App Store Linking.openURL( `itms-apps://itunes.apple.com/app/viewContentsUserReviews/id${itunesItemId}?action=write-review` );

API

import * as StoreReview from 'expo-store-review';

Methods

StoreReview.hasAction()

Android
iOS
Returns:
Promise<boolean>

This returns a promise that fulfills to true if StoreReview.requestReview() is capable directing the user to some kind of store review flow. If the app config (app.json) does not contain store URLs and native store review capabilities are not available then the promise will fulfill to false.

Example

if (await StoreReview.hasAction()) { // you can call StoreReview.requestReview() }

StoreReview.isAvailableAsync()

Android
iOS

Determines if the platform has the capabilities to use StoreReview.requestReview().

Returns:
Promise<boolean>

This returns a promise fulfills with boolean, depending on the platform:

  • On iOS, it will resolve to true unless the app is distributed through TestFlight.
  • On Android, it will resolve to true if the device is running Android 5.0+.
  • On Web, it will resolve to false.

StoreReview.requestReview()

Android
iOS

In ideal circumstances this will open a native modal and allow the user to select a star rating that will then be applied to the App Store, without leaving the app. If the device is running a version of Android lower than 5.0, this will attempt to get the store URL and link the user to it.

Returns:
Promise<void>

StoreReview.storeUrl()

Android
iOS

This uses the Constants API to get the Constants.expoConfig.ios.appStoreUrl on iOS, or the Constants.expoConfig.android.playStoreUrl on Android.

On Web this will return null.

Returns:
string | null

错误代码

ERR_STORE_REVIEW_FAILED

当商店评价请求未成功时会发生此错误。