Appstore Billing Compatibility SDK Best Practices
Follow these best practices when integrating your app with the Appstore Billing Compatibility SDK.
Improve app startup time
Calls to the Appstore Billing Compatibility APIs on app startup can increase the time it takes for the app to launch, resulting in a poor customer experience. As a best practice, the Amazon Appstore recommends that you make these server-side calls in the background to avoid delays when your app loads.
Avoid blocking the UI from loading
In the Fetch purchases integration guide, you are instructed to call queryPurchasesAsync()
in the onResume()
method to query customers' purchases. This API requires a server-side call to Amazon's server. Unlike the queryPurchasesAsync()
method in Google Play Billing, the queryPurchasesAsync()
method in the Appstore Billing Compatibility SDK makes a network call, which affects the time it takes for the listener callback to occur.
To prevent startup delays, don't block your UI from loading while your app waits for a response from Amazon's server. Instead, the Appstore recommends that you use the last purchase state that you have cached in your back-end server or in the app.
After you receive a response from queryPurchasesAsync()
, update your app's UI asynchronously to reflect any changes in the customer's purchase data.
queryPurchasesAsync()
call.Use the following diagrams to help visualize what happens when making Appstore Billing Compatibility API calls while an app loads.
Typical flow: Appstore Billing Compatibility API calls block the UI from loading
This diagram shows the steps from app launch to app UI load when Appstore Billing Compatibility API calls block the UI from loading.
- The user clicks on the app to launch it.
- A black screen is displayed while the app UI loads.
- The app begins to start up. In
onResume()
, the app callsqueryPurchasesAsync()
on the UI thread. A network call is made to fetch purchase details. During this time, the user continues to see a black screen. - The app grants access of the purchased items to the customer.
- The app continues loading the UI by showing the splash screen.
In this typical flow, a customer sees a black screen for several seconds as the Appstore Billing Compatibility API calls are made, which gives the perception that app launch is slow.
Recommended flow: Appstore Billing Compatibility API calls are made in the background
This diagram shows the steps from app launch to app UI load, when the Appstore Billing Compatibility API calls are made in the background.
- The app stores past purchase data in a back-end server or cache.
- The user clicks on the app to launch it.
- The app displays the splash screen and loads the UI based on the past data. The app does not check for purchase data from the server.
-
In the background, the app calls
queryPurchasesAsync()
. The UI isn't blocked from loading.The
queryPurchasesAsync()
API takes aPurchasesResponseListener
object as parameter. You can add logic to update the app UI in thePurchasesResponseListener
object'sonQueryPurchasesResponse()
method. - Synchronize your cache (or back end) with the new data.
- If needed, update or switch the UI to block or unblock the user from accessing content.
Related topics
- Appstore Billing Compatibility SDK—overview and integration guide
- Implement the Google Play Billing Interface
- Appstore Billing Compatibility Subscriptions
- Appstore Billing Compatibility SDK Troubleshooting
- Appstore Billing Compatibility API Reference
Last updated: Oct 14, 2024