我无法在应用程序购买中重新购买 - 消耗品

Posted

技术标签:

【中文标题】我无法在应用程序购买中重新购买 - 消耗品【英文标题】:I cannot re-purchase in app purchase - consumables 【发布时间】:2012-09-15 15:42:18 【问题描述】:

我正在做一个“应用内购买 - 消耗品”系统。第一次可以正常购买,但是下次尝试购买时,就不行了。所以我换了一个测试用户,它也只能第一次购买。显示“SK payment transaction state failed”,我该如何解决?

- (void)buyProduct:(int)myNumber
    SKPayment *payment = [SKPayment paymentWithProductIdentifier:[appDelegate.ArrayProductName objectAtIndex:myNumber]];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];


- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions

    for (SKPaymentTransaction *transaction in transactions)
        switch (transaction.transactionState) 
            case SKPaymentTransactionStatePurchasing:

                break;
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
                [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
                break;
            case SKPaymentTransactionStateFailed:
                if (transaction.error.code != SKErrorPaymentCancelled)
                    NSLog(@"An error encounterd : %@",transaction.error.code);
                
                break;
            default:
                break;
        
    


- (void)completeTransaction:(SKPaymentTransaction *)transaction  
    [self verifyReceipt:(SKPaymentTransaction *)transaction];


- (void)restoreTransaction:(SKPaymentTransaction *)transaction 



- (BOOL)verifyReceipt:(SKPaymentTransaction *)transaction 
    NSString* jsonObjectString =  [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];    
    NSString* completeString = [NSString stringWithFormat: @"myurl?receipt=%@", jsonObjectString];
    NSURL* urlForValidation = [NSURL URLWithString: completeString];
    NSMutableURLRequest* validationRequest = [[NSMutableURLRequest alloc] initWithURL: urlForValidation];
   [validationRequest setHTTPMethod: @"GET"];
    NSData * responseData = [NSURLConnection sendSynchronousRequest:validationRequest  returningResponse: nil  error: nil];
    NSString* responseString = [[NSString alloc] initWithData: responseData encoding: NSUTF8StringEncoding];
    NSLog(@"return data : %@",responseString);
    int success = [responseString intValue];
    return (success == 0);

【问题讨论】:

【参考方案1】:

我尝试购买。系统提示“您已经购买了这个,但尚未下载。点击确定立即下载”

是否需要先将数据发送到Apple的服务器,以便完整的系统以php为链接重新购买?

http://www.phpriot.com/articles/verifying-app-store-receipts-php-curl

http://developer.apple.com/library/ios/#releasenotes/StoreKit/IAP_ReceiptValidation/_index.html#//apple_ref/doc/uid/TP40012484

【讨论】:

以上是关于我无法在应用程序购买中重新购买 - 消耗品的主要内容,如果未能解决你的问题,请参考以下文章

iOS 应用内购买。识别购买的产品(非消耗品)。

如何恢复消耗品应用内购买?

iOS 非消耗性购买是不是与使用帐户或设备绑定?

将离线地图作为应用内购买出售

免费应用内购买

应用内购买:消耗品还是非消耗品?