基本クラス
クラス
クラス | 説明 |
---|---|
InAppProduct | ストアに登録された商品。 |
InAppStore | アプリ内購入を管理するためのメインエントリーポイント。 |
InAppTransaction | 外部アプリストアでのトランザクションに関する情報を含みます。 |
InAppPurchaseBackend | 外部ストアと通信します。 |
InAppProduct
InAppProductは、外部ストアの商品がInAppStoreに登録され、存在することが確認された後にカプセル化されます。外部ストアの商品の識別子と一致する識別子を持ち、外部ストアから取得した価格を持ち、商品タイプを持ちます。
商品タイプは、Consumable
またはUnlockable
である。 消耗品は、各トランザクションがアプリケーションによって明示的に確定される限り、何度でも購入することができる。アンロック可能なタイプは 1 回のみ購入できます。
InAppProduct には、5 つの返却可能変数price
、title
、description
、identifier
、productType
があります。productType 以外はすべてQString を返します。
ProductType は列挙型で、Consumable の場合は0
を、Unlockable の場合は1
を返します。
enum ProductType { Consumable, Unlockable };
Android用の派生クラスAndroidInAppProduct
、iOS用の派生クラスIosInAppProduct
。
InAppStore
アプリ内課金を管理するための主要なエントリポイントです。AndroidInAppProduct
とIosInAppProduct
の基本クラスです。
InAppStoreは、クロスプラットフォームでアプリケーション内のアプリ内課金を管理するために使用されます。コンパイラによって、InAppStore はMacros
を使用して利用可能なプラットフォームをチェックします。
void InAppStore::setupBackend() { #ifdef Q_OS_ANDROID d->backend = new AndroidInAppPurchaseBackend; #endif #ifdef Q_OS_IOS d->backend = new IosInAppPurchaseBackend; #endif d->backend->setStore(this); ...
ストアの初期化
デモのストアページに移動すると、InAppStoreはすべてのシグナルをsetupBackend()関数内の関連スロットに接続する。次にregisterProduct()関数を使用して、外部ストアに登録されている各商品の商品IDとproductTypeをQHash registeredProductsに登録します。
商品の登録は非同期で行われ、外部ストアから商品が見つかるとproductRegistered()シグナルが発生します。
void InAppStore::registerProduct(InAppProduct *product) { d->registeredProducts[product->identifier()] = product; emit productRegistered(product); }
購入の完了
ストアへの商品登録が完了したら、アプリのストアページから商品を選んで購入することができます。QMLはAndroidInAppProductまたはIosInAppProduct
、product.purchase()関数を呼び出し、外部ストアの購入フローを開きます。
購入が完了すると、transactionRedy シグナルがInAppProductQmlType
に送られ、QML にトランザクションの完了を通知します。
購入の復元
デモでは、アンロック可能な購入はアプリのストレージに保存されます。ストレージをクリアすることで、ユーザーはアンロック可能な購入を失い、外部ストアによると既に所有されているため、再度購入することはできません。
アプリストアページのrestore purchases
ボタンを使用して、アンロック購入した商品を復元することができます。購入履歴の復元ボタンはrestorePurchases()関数を呼び出し、外部ストアにすでに所有されている購入履歴がないかチェックします。transactionRedy()シグナルを発信し、購入を確定して復元します。
InAppStoreには派生クラスはありません。
InAppTransaction
InAppTransactionは、外部アプリストアでのトランザクションに関する情報を含み、通常はInAppProduct::purchase()を呼び出した結果として提供されます。購入フローがユーザーによって完了されると(パスワードを入力するなどして購入を確認する)、製品を含む InAppStore インスタンスは、トランザクションに関するデータを含む InAppStore::transactionReady() シグナルを発行します。
status()関数は、トランザクションが成功したかどうかの情報を提供する。成功した場合、アプリケーションは適切なアクションを実行する必要があります。必要なアクションが実行されたら、finalize() を呼び出す。finalize()関数は、トランザクションのステータスに関係なく呼び出されなければならない。
android用の派生クラスAndroidInAppTransaction
、iOS用の派生クラスIosInAppTransaction
。
InAppPurchaseBackend
InAppPurchaseBackend
は、 と の派生クラスの作成に使用される。AndroidInAppPurchaseBackend
IosInAppPurchaseBackend
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.