如何从应用内托管内容下载内容?

时间:2013-10-23 05:52:44

标签: ios in-app-purchase

当我从App Store下载内容时,它开始工作并显示

进度:0.000000

剩余:-1.000000

进度:0.000000

剩余:-1.000000

进展:0.750000

剩余:0.220680

最后显示失败。

这是我用过的代码

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction * transaction in transactions) {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];
                break;
            case SKPaymentTransactionStateFailed:
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
                break;
            default:
                break;
        }
    };
}

-(void) paymentQueue:(SKPaymentQueue *)queue updatedDownloads:(NSArray *)downloads
{
    for (SKDownload *download in downloads)
    {
        switch (download.downloadState)
        {
            case SKDownloadStateActive:
            {
                NSLog(@"progress: %f", download.progress);
                NSLog(@"%f remaining", download.timeRemaining);
                break;
            }

            case SKDownloadStateCancelled: { break; }
            case SKDownloadStateFailed:
            {
                NSLog(@"faild");
                break;
            }

            case SKDownloadStateFinished:
            {
                NSString *source = [download.contentURL relativePath];
                NSDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:[source stringByAppendingPathComponent:@"ContentInfo.plist"]];

                NSLog(@"%@", dict); 

                [[SKPaymentQueue defaultQueue] finishTransaction:download.transaction];
                break;
            }

            case SKDownloadStatePaused:
            {
                NSLog(@"SKDownloadStatePaused");
                break;
            }

            case SKDownloadStateWaiting:
            {
                NSLog(@"SKDownloadStateWaiting");
                break;
            }
        }
    }

}

我现在怎样才能获得文件?

0 个答案:

没有答案