アプリストアのレシート はデバイスのローカルストレージに保管されており、以下のようにして読むことができます。
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
string receipt = builder.Configure<IAppleConfiguration>().appReceipt;
アプリ内課金はデバイスの設定で制限されている場合があります。以下のようにして、確認できます。
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
bool canMakePayments = builder.Configure<IAppleConfiguration>().canMakePayments;
Apple のプラットフォーム上では、前回のトランザクションを取得するには、リストアするかどうかのボタンを表示して、ユーザーからパスワードを入力してもらわなくてはなりません。トランザクションの復元中、IStoreListener
の ProcessPurchase
は、ユーザーがすでに所有しているアイテムすべてに実行されます。
/// <summary>
/// OnInitialized の IStoreListener 実装
/// </summary>
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
extensions.GetExtension<IAppleExtensions> ().RestoreTransactions (result => {
if (result) {
// なにかがリストアされたというわけではありません
// 単に復元の処理が終了したということです
} else {
// 復元失敗
}
});
}
Apple は、サーバーから新しいアプリ レシートをフェッチする方法を提供しています。この方法は通常、レシートが現在ローカルにキャッシュされていない場合に使用できます。SKReceiptRefreshRequest
この方法にはパスワードが必要だということに気を付けてください。
Unity IAP では以下のようにこのメソッドを使用します。
/// <summary>
/// OnInitialized の IStoreListener 実装
/// </summary>
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
extensions.GetExtension<IAppleExtensions> ().RefreshAppReceipt (receipt => {
// リクエストが成功したら、このハンドラーが呼び出されます
// レシートは最新の App Store レシート
Console.WriteLine(receipt);
},
() => {
// リクエストが失敗したら、このハンドラーが呼び出されます。
// 例えば、ネットワークが使用不可であったり、
// ユーザーが誤ったパスワードを入力した場合など。
});
}
iOS 8 からペアレンタルコントロールに新しい機能が追加されました。Ask to Buy
Ask to Buy は子供が課金を行う前に親の許可を求める機能です。この機能を使うと Unity IAP は以下のようにリスナーを登録することでアプリが通知を受け取ることができるようになります。
/// <summary>
/// This will be called when Unity IAP has finished initialising.
/// </summary>
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
extensions.GetExtension<IAppleExtensions>().RegisterPurchaseDeferredListener(product => {
Console.WriteLine(product.definition.id);
});
}
親が購入を許可したら通常イベントの ProcessPurchase、却下したら通常イベントの OnPurchaseFailed が呼び出されます。
Apple ストアでテストをするには ITunes Connect でテストアカウントを作成し、そのテストアカウントで iTunes に接続しなければいけません。
iOS デバイスや Mac でストアからサインアウトして、アプリを起動し、課金やリストアを行うときにどのアカウントでログインするかを求められます。
NoProductsAvailable
が原因で初期化に失敗したときは以下の内容を確認してください。
Unity のビルド設定で Mac のスタンドアロン用に Mac App Store validation
にチェックを入れておく必要があります。
アプリをビルドしたら、info.plist のバンドル ID とバージョン設定を更新する必要があります。.app
ファイル上で右クリックして パッケージの内容を表示
を選択し、info.plist
ファイルの CFBundleIdentifier
の値をアプリのバンドル ID へと変更します。
そして署名をした後に、パッケージとアプリをインストールします。そのための操作は Mac OSX 上のターミナルで行います。
codesign -f --deep -s "3rd Party Mac Developer Application: " your.app/Contents/Plugins/unitypurchasing.bundle
codesign -f --deep -s "3rd Party Mac Developer Application: " your.app
productbuild --component your.app /Applications --sign "3rd Party Mac Developer Installer: " your.pkgstaller: " your.pkg`
バンドルに署名するには、Contents.meta ファイルが存在する場合、まずこれを削除する必要があります。your.app/Contents/Plugins/unitypurchasing.bundle/Contents.meta
正しくパッケージをインストールするには、新しく作成したパッケージを実行する前にパッケージ化していない .app ファイルを削除しておく必要があります。
そして、アプリケーション フォルダーからアプリを起動します。初回は iTunes アカウントの詳細を入力するよう求められるので、iTunes Connect で作成したテストアカウントでログインします。これでテストアカウントがサンドボックス環境で課金を行うことができます。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.