【发布时间】: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;
}
}
}
我已经查看了堆栈溢出和其他地方,我可以在应用购买中找到的一些小示例都与上述相同。任何帮助或信息都会很棒。
【问题讨论】: