1.原因
この現象はSKRequestの下位APIであるSKProductsRequestのdelegateで処理完了時(正常及びエラー系delegate呼び出し)、トランザクションの完了通知が適切に行われていない場合に発生する。
キューが解放されていないため、キューの有効期限が達するまで次のキューが処理されないのが理由である。
2. 対策
(1) 下記メソッドを追加する。
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error;
- (void)requestDidFinish:(SKRequest *)request;
(2) updatedTransactionsメソッドで、SKPaymentTransactionStatePurchased、SKPaymentTransactionStateFailed、SKPaymentTransactionStateRestoredのときに、トランザクションの完了通知が実行されていない場合は、記述する。
[queue finishTransaction:transaction];
SKProductsRequestは強参照にしておかないと、リクエストがOS制御により消去されることがある。
処理はメインスレッドで行われないので、delegateが呼び出された後のUI構築はメインスレッドで実行するように明示すること。
参考記事:
https://stackoverflow.com/questions/9935054/storekit-delegate-method-not-getting-called
https://iganin.hatenablog.com/entry/2019/10/09/014932
https://developer.apple.com/documentation/storekit/skproductsrequest?language=objc
https://developer.apple.com/documentation/storekit/skproductsrequestdelegate?language=objc
https://developer.apple.com/documentation/storekit/skrequestdelegate/1385536-request?language=objc
https://githubmemory.com/repo/tikhop/TPInAppReceipt/issues/74
https://github.com/RevenueCat/purchases-ios/pull/418
https://github.com/RevenueCat/purchases-ios/issues/391
【アプリ内課金の最新記事】