ios - 应用内购买 - 无需恢复购买

标签 ios objective-c in-app-purchase

我正在尝试确定当用户尝试恢复应用内购买但从未进行过购买时我是否会收到消息。

现在,只要用户点击 restoreButton,我就会禁用 restoreButton

- (IBAction)purchaseRestore:(id)sender {
    NSLog(@"4 IBAction Purchase Restore Method: start");
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue]restoreCompletedTransactions];
    NSLog(@"4 Purchase Restore: SKPayment Queue two lines... log in user");
    restoreButton.enabled = NO;
    NSLog(@"4 Restore button enabled: No");
}

因此,如果他们单击 restoreButton,并且没有任何要恢复的内容,那么 restoreButton 只会保持灰色。

我想做一些类似 UIAlert 的事情,或者更改 restoreButton 文本,如果这恰好显示“您没有任何要恢复的项目” ,但我想我需要从 Apple 那里得到一些消息,说“没有要恢复的项目”,这样我才能触发该代码。

如果需要,这是我的 updatedTransactions 代码:

case SKPaymentTransactionStateRestored:

                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                NSLog(@"5 Finish Transaction");

                restoreButton.hidden = YES;
                NSLog(@"5 restore button hidden: Yes");

                [self showButtonThree];
                NSLog(@"5 Show Button Three");

                NSLog(@"5 Restored: End");

                break;

有什么想法吗?谢谢!

更新

试过这个:

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
    NSLog(@"Completed Transactions Finished");
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                              @"Restored succesfully" message:nil delegate:
                              self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    [alertView show];
}

但是无论是否有要恢复的事务都会弹出。我原以为如果没有要恢复的事务可能会被调用,但它不会被调用是有道理的:

-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error {
    NSLog(@"Completed Transactions Failed with Error");
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                              @"Not restored succesfully" message:nil delegate:
                              self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    [alertView show];
}

最佳答案

来自 Apple 官方文档 restoreCompletedTransactions

After the transactions are delivered, the payment queue calls the observer’s paymentQueueRestoreCompletedTransactionsFinished: method. If an error occurred while restoring transactions, the observer will be notified through its paymentQueue:restoreCompletedTransactionsFailedWithError: method.

关于ios - 应用内购买 - 无需恢复购买,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25353176/

相关文章:

ios - IAP iOS Objective c 中的 SKErrorDomain Code=0 "Cannot connect to iTunes Store"

ios - 重新排列 MediaPlayer 音乐队列 [iOS]

ios - swift - 如何修改另一个类的对象的属性?

objective-c - 仅显示 uiimage 的一部分

ios - 获取 iPhone 所在的国家(没有 CLLocationManager)

iphone - 在 IOS SDK 中处理多个本地通知

google-api - 服务帐户 (403) Forbidden Google Play In-app Billing Purchase Status API

ios - 如何在 iOS 的特定时间每天更改 View Controller

ios - 无论如何,当我的应用程序在iOS App中处于前台时,是否可以停止屏幕锁定?

android - 应用内计费 (v3) - 了解空指针异常