Use the AppReviewService API
- Import AppReviewService into your component definition to make the AppReviewService API functions available to your code.
- Test to make sure AppReviewService is available before you call app feedback functions.
- Use the app review functions to ask users app review related questions.
Import AppReviewService into a Component
In your component’s JavaScript file, import AppReviewService using the standard JavaScript import statement. Specifically, import the getAppReviewService() factory function from the lightning/mobileCapabilities module, like so:
import { getAppReviewService } from 'lightning/mobileCapabilities';
After it’s imported into your component, use the factory function to get an instance of AppReviewService. With your AppReviewService instance, use the utility functions and constants to verify availability. Use the app review related functions to perform app review operations.
Test AppReviewService Availability
AppReviewService depends on physical device hardware and platform features. A component that uses AppReviewService renders without errors on a desktop computer or in a mobile browser, but app review functions fail. To avoid these errors, test if AppReviewService functionality is available before you use it.
handleBeginClick(event) {
const myAppReviewService = getAppReviewService();
if(myAppReviewService.isAvailable()) {
// Perform app review related operations
}
else {
// AppReviewService not available
// Handle with message, error, beep, and so on
}
}
Request an App Review
It’s straightforward to create an app review feature using AppReviewService.
- Start a review request with requestAppReview().
- Handle the results of the app review request.
For example:
myAppReviewService.requestAppReview(null)
.then(() => {
// Do something with success response
console.log("App review request complete successfully");
})
.catch((error) => {
// Handle cancelation and scanning errors here
console.error(error);
});
See requestAppReview() for more details about how to handle errors.