Я включил ежемесячную подписку в свое приложение, для этого я использую автообновление при покупке приложения.Со сборкой SandBox все работает нормально, но при тестировании сборки через TestFlight у меня возникают две проблемы.
- После успешной покупки приложение все еще просит подтвердить пароль Apple ID с сообщением " Введите пароль для Apple ID xxxxxx.xxxx.xx, чтобы подтвердить учетную запись iTunes и разрешить этому устройству подтверждать покупки. "
- После удаления и повторной установки приложения я пытаюсьчтобы купить предыдущий товар, и приложение показывает всплывающее окно с текстом «Вы в настоящее время подписаны .......... Управление. ОК.» Когда я нажимаю на Ok,Ничего не произошло.Я думаю, что в этот момент "updatedTransactions" делегат должен быть вызван с TransactionStatePurchased , но ничего не происходит.или может быть, что-то происходит, но я не знаю, как отладить это в сборке TestFlight.
Я добавил наблюдателя транзакции в AppDelegate
/*
* ----------------- FOLLOWING ARE OBSERVERS FOR PAYMENT TRANSACTION ----------------------------
*/
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions
{
NSLog(@"Count = %lu",(unsigned long)transactions.count);
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchasing:
{
NSLog(@"1. Transaction is in Purchasing state");
[self handlePurchasingStateFor:transaction withQueue:queue];
break;
}
case SKPaymentTransactionStatePurchased:
{
NSLog(@"2. Transaction is in Purchased state");
[self handlePurchasedStateFor:transaction withQueue:queue];
break;
}
case SKPaymentTransactionStateFailed:
{
NSString *failMsg = [[NSString alloc]initWithFormat:@"Purchase failed with error: %@",transaction.error.localizedDescription];
NSLog(@"3. Error Mesg - %@",failMsg);
[self handleFailStateFor:transaction withQueue:queue];
break;
}
case SKPaymentTransactionStateRestored:
{
NSLog(@"4. Transaction is Restored");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[self handleRestoreStateFor:transaction withQueue:queue];
break;
}
case SKPaymentTransactionStateDeferred:
{
NSLog(@"5. Transaction is deffered, waiting for parent approval");
[self handleDefferedStateFor:transaction withQueue:queue];
break;
}
}
}
}
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
if (queue.transactions.count > 0)
{
NSDictionary* userInfo = @{@"error": @"Subscription restored successfully."};
[[NSNotificationCenter defaultCenter] postNotificationName:InAppServicerestoreSuccessful object:self userInfo:userInfo];
}
else
{
NSDictionary* userInfo = @{@"error": @"There is no product to restore."};
[[NSNotificationCenter defaultCenter] postNotificationName:InAppServicerestoreFail object:self userInfo:userInfo];
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
NSDictionary* userInfo = @{@"error": @"Restore failed, please try again later"};
[[NSNotificationCenter defaultCenter] postNotificationName:InAppServicerestoreFail object:self userInfo:userInfo];
}
/*
* ------------------------------ CUSTOM METHODS TO HANDLE IN APP STATUS -----------------------
*/
-(void)handlePurchasingStateFor:(SKPaymentTransaction*)transaction withQueue:(SKPaymentQueue*)queue {
NSLog(@"User is attempting to purchase product id: %@",transaction.payment.productIdentifier);
}
-(void)handlePurchasedStateFor:(SKPaymentTransaction*)transaction withQueue:(SKPaymentQueue*)queue {
NSLog(@"User purchased product id: %@",transaction.payment.productIdentifier);
[queue finishTransaction:transaction];
NSDictionary* userInfo = @{@"error": @"Purchase is successful, you are all set."};
[[NSNotificationCenter defaultCenter] postNotificationName:InAppServicepurchaseSuccessful object:self userInfo:userInfo];
}
-(void)handleRestoreStateFor:(SKPaymentTransaction*)transaction withQueue:(SKPaymentQueue*)queue {
NSLog(@"User restored product id: %@",transaction.payment.productIdentifier);
[queue finishTransaction:transaction];
}
-(void)handleFailStateFor:(SKPaymentTransaction*)transaction withQueue:(SKPaymentQueue*)queue {
NSLog(@"User failed to purchase product id: %@",transaction.payment.productIdentifier);
}
-(void)handleDefferedStateFor:(SKPaymentTransaction*)transaction withQueue:(SKPaymentQueue*)queue {
NSLog(@"App is waiting for parental permission for product id : %@",transaction.payment.productIdentifier);
}
![enter image description here](https://i.stack.imgur.com/Ff2Hp.png)