如何从恢复的事务中获取产品标识符?

时间:2012-02-20 10:05:41

标签: iphone ios in-app-purchase

我已设法恢复应用内交易并从原始交易中获取交易标识符,但如何识别在交易中购买的产品? 是否可以获取以前购买的应用内商品的产品标识符?

2 个答案:

答案 0 :(得分:57)

如果您的意思是想要检查已购买的商品,那么用户可以购买它......是的,您可以这样做

- (void) checkPurchasedItems
{
   [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}//You Call This Function

//Then this delegate Function Will be fired
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
purchasedItemIDs = [[NSMutableArray alloc] init];

NSLog(@"received restored transactions: %i", queue.transactions.count);
for (SKPaymentTransaction *transaction in queue.transactions)
{
    NSString *productID = transaction.payment.productIdentifier;
    [purchasedItemIDs addObject:productID];
}
}

答案 1 :(得分:6)

SWIFT VERSION:

获得代表后

func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!) {
    var productIds = [String]()
    for transcation in queue.transactions{
        if let productID = transcation.payment?.productIdentifier{
        productIds.append(productID)
        }
    }