LoginSignup
26
23

More than 5 years have passed since last update.

アプリ内課金の追加

Last updated at Posted at 2017-04-26

「SenchaTouch + Cordova」のiOS、Androidアプリ開発ではまったことを少しメモする。

プラグイン追加

iOSのみ対応する場合:

$ cd cordova
$ cordova plugin add cc.fovea.cordova.purchase

Androidも対応する場合:

$ cd cordova
$ cordova plugin add cc.fovea.cordova.purchase --variable BILLING_KEY="ライセンスキー"

参考元:https://github.com/j3k0/cordova-plugin-purchase

iOSの実装メモ

問題1

fatal error: '''Foundation/Foundation.h''' file not found

解決:

StoreKit.frameworkが正しくリンクされていませんでした。
Xcode6.1 -> Xcode6.1.1 へアップデートすることで解決

問題2

問題1の影響かもしれないですが、
Build Phases -> Compile Sources -> InAppPurchase.m が正しく追加されていません。
※ Xcode6.1.1更新後に、別のアプリだったら問題ありませんでした。

解決:

手動で InAppPurchase.m を追加しました。

Androidの実装メモ

問題1

認証エラー:<認証が必要です。Googleアカウントにログインしてください。>

解決:

開発者以外のアカウントで試すとうまくいった。

Javascript側の簡単なサンプル

複数登録の際に、参考元にある registerProducts メソッドがなぜかうまく動作できず、下記のように一個一個登録します。

// イベント登録
document.addEventListener('deviceready', initializeStore, false);

function initializeStore() {
    // 購入登録
    store.register({
      id: "product.id1",
      type: store.CONSUMABLE
    });
    store.register({
      id: "product.id2",
      type: store.CONSUMABLE
    });

    // 購入完了イベント
    store.when("product.id1").approved(function(product) {
        product.finish();
    });

    // プレミアムチェック
    store.when("product.id1").updated(checkIsPremium);

    // エラーハンドリング
    store.error(function(e){
        console.log("ERROR " + e.code + ": " + e.message);
    });

    // 準備完了
    store.ready();

    // 更新
    store.refresh();
}

// プレミアムチェック 個別
function checkIsPremium(product) {
    if (product.owned) {
        window.isPremium = true;
    } else {
        window.isPremium = false;
    }
}

// アイテムの購入方法
store.order("product.id1");

// アイテムの復元方法
store.restore();

実装済みアプリ

26
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
23