从暂停状态进入应用程序后,应用程序内购买ios购买状态更新

时间:2014-04-23 06:48:28

标签: ios objective-c in-app-purchase

non-consumable product拥有托管内容,购买成功完成。但是,在将应用留给suspended state时,我认为是download process stops。再次进入app下载restarts by updated transactions。 在下载过程中suspended state or wifi-off state期间实际发生了什么?

谢谢

    - (void) purchase: (CDVInvokedUrlCommand*)command
    {
        DLog(@"About to do IAP");
        if([SKPaymentQueue canMakePayments]){
            id identifier = [command.arguments objectAtIndex:0];
            id quantity =   [command.arguments objectAtIndex:1];
            SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:[self.list objectForKey:identifier]];
            if ([quantity respondsToSelector:@selector(integerValue)]) {
                // payment.quantity = [quantity integerValue];
            }
            [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
            [[SKPaymentQueue defaultQueue] addPayment:payment];
        }
        else{
            NSLog(@"Can't make payments");
        }
    }    
- (void)paymentQueue:(SKPaymentQueue*)queue updatedTransactions:(NSArray*)transactions
    {
        NSString *state, *error, *transactionIdentifier, *transactionReceipt, *productId;
        NSInteger errorCode;

        for (SKPaymentTransaction *transaction in transactions)
        {
            error = state = transactionIdentifier = transactionReceipt = productId = @"";
            errorCode = 0;
            DLog(@"Payment transaction updated:");
            BOOL startFinish=FALSE;
            switch (transaction.transactionState)
            {
                case SKPaymentTransactionStatePurchasing:
                //DLog(@"Purchasing...");
                continue;

                case SKPaymentTransactionStatePurchased:
                    state = @"PaymentTransactionStatePurchased";
                    transactionIdentifier = transaction.transactionIdentifier;
                    transactionReceipt = [[transaction transactionReceipt] base64EncodedString];
                    productId = transaction.payment.productIdentifier;
                    [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:productId];
                    if(transaction.downloads){
                        [[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];
                    }
                    else{
                        startFinish=TRUE;
                    }
                break;

                case SKPaymentTransactionStateFailed:
                    state = @"PaymentTransactionStateFailed";
                    error = transaction.error.localizedDescription;
                    errorCode = transaction.error.code;
                    startFinish=TRUE;
                    [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
                break;                
                case SKPaymentTransactionStateRestored:
                    NSLog(@"transaction payment restoreed");
                    state = @"PaymentTransactionStateRestored";
                    transactionIdentifier = transaction.originalTransaction.transactionIdentifier;
                    transactionReceipt = [[transaction transactionReceipt] base64EncodedString];
                    productId = transaction.originalTransaction.payment.productIdentifier;
                    if(transaction.downloads){
                        [[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];
                    }
                    else{
                        startFinish=TRUE;
                    }
                break;

                default:
                DLog(@"Invalid state");
                continue;
            }

            if(startFinish){
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            }
        }
    }
-(void)paymentQueue:(SKPaymentQueue *)queue updatedDownloads:(NSArray *)downloads
{
    for (SKDownload *download in downloads)
    {
        switch (download.downloadState) {
            case SKDownloadStateActive:
               // NSLog(@"progress url : %@" , [download.contentURL absoluteString]);
                NSLog(@"Download progress = %f and Download time: %f", download.progress, download.timeRemaining);
                break;
            case SKDownloadStateCancelled:
                NSLog(@"cancelled");
                break;
            case SKDownloadStatePaused:
                NSLog(@"Paused");
                break;
            case SKDownloadStateWaiting:
                NSLog(@"waiting");
                break;
            case SKDownloadStateFinished:
                NSLog(@"Finished");
                [[SKPaymentQueue defaultQueue] finishTransaction:download.transaction];
                break;
            case SKDownloadStateFailed:
                break;
            default:
                break;
        }        
    }    
}

0 个答案:

没有答案