FMX.CapitalIAP Sample

From RAD Studio Code Examples
Jump to: navigation, search

This is a sample that shows the use of in-app payment and advertisement services in mobile applications using FireMonkey.

Location

You can find the CapitalTrivia sample project at:

Description

This application illustrates how to use:

TBannerAd will connect to your ads services and display ads inside your app. Using the TInAppPurchase component you can disable these ads.

The purchasable content must be registered in Google developer console for Android and iTunes connect for iOS and are managed by the store services. This sample demonstrates how to disable ads and how to add new content in your app, in our case European capitals questions for the trivia.

How to Use the Sample

  1. Navigate to the either of the locations given above.
  2. Open the project file:
    • Delphi: CapitalTrivia.dproj
    • C++: CapitalTriviaCpp.cbproj
  3. Follow the steps below.

Define the Required Products

On the constants definition section of the Main unit, the application defines the ID of two products. You must define in your store (Google Play, iTunes or both) two new products with the same properties as these two non-consumable products:

Delphi:

const
  EuropeID = 'com.embarcadero.capitals.europe';
  NoAdsID = 'com.embarcadero.capitals.noads';

C++:

const String EuropeID = "com.embarcadero.capitals.europe";
const String NoAdsID = "com.embarcadero.capitals.noads";

To define these products in your store, follow the instructions bellow for your in-app payment service or services:

Google Play In-app Billing iOS In-App Purchase
Prerequisites Prerequisites
Configuring Your Application for In-app Billing in Google Play Configuring Your Application for In-App Purchase in iTunes Connect

After you define these products in your store, update Main.pas with the actual IDs that you specified in your store for these four products.

Configure Your Google Keys

For the Google Play In-app Billing service, you must follow the instructions at Establishing a Connection to the Google Play In-app Billing Service. You must provide your application license key in the ApplicationLicenseKey property, which the sample sets on the FormCreate event handler. See Configuring the Connection Data for the Google Play In-app Billing Service.

For the AdMob service, you must follow the instructions at Configuring the Connection Data for AdMob. You must provide your ad unit ID in the AdUnitID property, which the sample sets on the InAppPurchaseSetupComplete event handler.

Run the Sample Application on a Device

Once your products are configured, you can proceed to run the application on an Android or iOS device. See:

Note: Android emulators and the iOS simulator do not support in-app purchases.

To test this application without actually publishing it in your application store or incurring charges, see:

Platform Advertising service In-app billing service

Android

AdMob
Testing Your Ads

Google Play In-app Billing
Testing Your In-App Purchase Products

iOS

iAd
Testing Your iAds

iOS In-App Purchase
Testing Your In-App Purchase Products

Once you open the application on a device, you can see a screen that lets you choose the number of questions about state capitals that you want to answer. This screen also shows an ad on the bottom and an information icon on the bottom-right corner that gives you access to the application settings.

CapitalTrivia.png

Use the Application

The basic use of the application is straightforward: you select the number of questions to answer and you try to answer them. More interesting are the settings.

Tap the information icon on the bottom-right corner of the main screen to open the application settings screen. In the settings, you can purchase questions about European capitals, as well as disable the ads on the bottom of the application.

CapitalTriviaSettings.png

Files

Unit Description

Answered

Form that shows after you answer a question.

Main

Main screen of the application.

This screen lets you choose between quizzes with a different number of questions, and gives you access to the application settings.

Option

Application settings.

You can configure the questions here, as well as purchase questions about Europe or remove the ads from the application.

Quiz

Form that shows a question during a quiz.

Score

Screen that shows after you answer the last question of a quiz.

Uses

See Also