Expo StoreReview
一个提供应用内评论原生 API 访问的库。
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。它允许你在不离开应用本身的情况下,请求用户为你的应用评分。
安装
- npx expo install expo-store-reviewIf you are installing this in an existing React Native app, make sure to install expo in your project.
使用
在使用此 API 时,遵循 iOS 的 Human Interface Guidelines 和 Android 的 Guidelines 非常重要。
具体来说:
- 不要从按钮中调用
StoreReview.requestReview()——而应尝试在用户完成应用中的某个标志性交互后再调用它。 - 不要刷屏打扰用户。
- 当用户正在进行诸如导航之类的时间敏感操作时,不要请求评论。
- 在展示评分按钮或卡片之前或期间,不要询问用户任何问题。
撰写评论
Android
Android 上没有对应的重定向,不过你仍然可以使用查询参数 showAllReviews=true 打开 Play 商店的评论区域,如下所示:
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 中某个应用的 “撰写评论” 界面。例如:
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
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() }
Determines if the platform has the capabilities to use StoreReview.requestReview().
Promise<boolean>This returns a promise fulfills with boolean, depending on the platform:
- On iOS, it will resolve to
trueunless the app is distributed through TestFlight. - On Android, it will resolve to
trueif the device is running Android 5.0+. - On Web, it will resolve to
false.
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.
Promise<void>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.
string | null错误代码
ERR_STORE_REVIEW_FAILED
当商店评论请求未成功时,会发生此错误。