私はこのコードとすべてのプロセスを持っていて、この状態に入ります: SKPaymentTransactionStatePurchased
しかし、サブスクリプションの試用期間が終了するとどうなるかわかりません。この実装は正しいですか?
一方、ユーザーがアプリケーションを再度実行すると、製品が既に購入されていることを確認するアラートが表示されます。アプリケーションが既に購入されているときにユーザーがアプリを再度開いたときに、このアラートを回避する方法は?
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self requestPurchasableRequest];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
-(void) requestPurchasableRequest{
NSString *identifier = @"com.xxx.xxx";
NSSet *productIdentifierSet = [[NSSet alloc]initWithObjects:identifier, nil];
SKProductsRequest *productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifierSet];
productRequest.delegate = self;
[productRequest start];
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
if (response.invalidProductIdentifiers.count>0) {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Warning"
message:@"This product is not available at this moment please try again later."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
}else {
products = response.products;
SKPayment *payment = [SKPayment paymentWithProduct:products[0]];
[[SKPaymentQueue defaultQueue]addPayment:payment];
}
-(void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStateDeferred:
break;
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
default:
break;
}
}
}