Reference version

This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo StoreReview iconExpo StoreReview

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

Android
iOS
Included in Expo Go
Recommended version:
~58.0.0

expo-store-review 是一个库,可在 Android 5 及更高版本上使用 ReviewManager API,并在 iOS 上使用 SKStoreReviewController API。它允许你在不离开应用的情况下请求用户为应用评分。

安装

Terminal
- npx expo install expo-store-review
- yarn expo install expo-store-review
- pnpm expo install expo-store-review
- bun 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 Store 的评价页面,如下所示:

Android Play Store example
const androidPackageName = 'host.exp.exponent'; // Open the Android Play Store in the browser -> redirects to Play Store on Android Linking.openURL( `https://play.google.com/store/apps/details?id=${androidPackageName}&showAllReviews=true` ); // Open the Android Play Store directly Linking.openURL(`market://details?id=${androidPackageName}&showAllReviews=true`);

iOS

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

iOS App Store example
const itunesItemId = 982107779; // Open the iOS App Store in the browser -> redirects to App Store on iOS Linking.openURL(`https://apps.apple.com/app/apple-store/id${itunesItemId}?action=write-review`); // Open the iOS App Store directly 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

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