我已将月度订阅集成到我的应用程序中,为此,我在应用程序购买中使用了自动更新功能。 SandBox构建一切正常,但是通过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);
}