嘗試以下操作:
在還原按鈕點擊 - >
- (IBAction)retoreinApp:(id)sender
{
//set addTransactionObserver to self.
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
這將調用
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
UIAlertView *alert ;
if(queue.transactions.count >0)
{
for (SKPaymentTransaction *transaction in queue.transactions)
{
NSString *productId = transaction.payment.productIdentifier;
NSLog(@" ProductIdentifier is %@",productId);
if([productId isEqualToString:@"com.xy.yourProductId"])
{//add code to add it to your account
}
alert = [[UIAlertView alloc ] initWithTitle:@"Restore Transactions" message:@"All your previous transactions are restored successfully." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
}
else
{
alert = [[UIAlertView alloc ] initWithTitle:@"Restore Transactions" message:@"No transactions in your account to be restored." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
}
[alert show];
}
順便說一句,你需要一個可見的「還原按鈕「,不只是代碼自動恢復 –
是的,我已經加入了! –