我們的應用程序向蘋果託管的額外內容提供了應用程序購買,用戶可以下載這些內容,但有些用戶報告下載有問題。iOS在SKDownloadStateFailed狀態下處理IAP下載失敗
它似乎中途失敗,提醒用戶並重置所有按鈕等以允許用戶再次購買(因爲他們已經購買了免費)。如果用戶嘗試重新購買或恢復應用中的購買,它仍然會失敗。以下代碼是處理失敗狀態的代碼。
-(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;
}
}
}
我看了看周圍堆棧溢出和其他地方和什麼小例子,我可以在應用內購買找到所有做上述相同。任何幫助或信息會很好。