【问题标题】:iOS Handle IAP download fail on SKDownloadStateFailed stateiOS 处理 IAP 下载在 SKDownloadStateFailed 状态下失败
【发布时间】:2014-01-14 09:50:55
【问题描述】:

我们的应用向用户下载的苹果托管的额外内容提供应用内购买,但一些用户报告下载存在问题。

似乎中途失败,提醒用户并重置所有按钮等以允许用户再次购买(因为他们已经购买了免费)。如果用户随后尝试在应用程序中重新购买或恢复购买,它仍然会失败。以下代码是处理失败状态的代码。

-(void) paymentQueue:(SKPaymentQueue *)queue updatedDownloads:(NSArray *)downloads{
for (SKDownload *download in downloads){
    switch (download.downloadState){
        case SKDownloadStateActive:{
            //code removed for post
            break;
        }  
        case SKDownloadStateCancelled:{ break; }
        case SKDownloadStateFailed:
        {
            //log the error
            NSLog(@"Transaction error: %@", download.transaction.error.localizedDescription);

            //let the user know
            [[[UIAlertView alloc] initWithTitle:@"Error!" message:[NSString stringWithFormat:@"%@ download failed, please try again later", download.contentIdentifier] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];

            //post notification - caught in view controller for updating buy buttons etc
            [[NSNotificationCenter defaultCenter] postNotificationName:IAPHelperDownloadFailedNotification object:download userInfo:nil];

            // This should delete the download assets from the Cache folder.
            NSError* error = nil;
            [[NSFileManager defaultManager] removeItemAtURL:download.contentURL error:&error];
            if(error){
                //
            }

            //finish the transaction
            [[SKPaymentQueue defaultQueue] finishTransaction:download.transaction];

            break;
        }

        case SKDownloadStateFinished:{
            //code removed for post
            break;
        }

        case SKDownloadStatePaused:{
            break;
        }

        case SKDownloadStateWaiting:{
            break;
        }
    }
}

我已经查看了堆栈溢出和其他地方,我可以在应用购买中找到的一些小示例都与上述相同。任何帮助或信息都会很棒。

【问题讨论】:

    标签: ios iphone ios7


    【解决方案1】:

    我遇到了类似的问题,刚刚在 Apple 的 IAP 常见问题解答中找到了可能的解决方案: 问:如何解决“您已经购买了此应用内购买但尚未下载”。错误信息? 答:您会收到“您已经购买了此应用内购买但尚未下载”。错误消息,因为您没有在应用程序中调用 SKPaymentQueue 的 finishTransaction:method。调用 finishTransaction: 允许您从支付队列中删除交易。

    我想我会要求我的 IAP 引擎在应用退出时检查是否有任何 IAP 正在处理(我的问题是当用户在下载时停止应用时出现的),如果是,则调用 finishTransaction:。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-15
      • 2019-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-28
      相关资源
      最近更新 更多