2014-01-14 41 views
1

我們的應用程序向蘋果託管的額外內容提供了應用程序購買,用戶可以下載這些內容,但有些用戶報告下載有問題。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; 
     } 
    } 
} 

我看了看周圍堆棧溢出和其他地方和什麼小例子,我可以在應用內購買找到所有做上述相同。任何幫助或信息會很好。

回答

0

我遇到了類似的問題,剛剛在蘋果的IAP常見問題解答中發現了一個可能的解決方案: 問:如何解決「您已經購買了此應用內購買,但尚未下載。」錯誤信息? 文章:你得到了「你已經購買了這個應用程序內購買,但它沒有被下載。」錯誤消息,因爲您沒有在應用程序中調用SKPaymentQueue的finishTransaction:方法。調用finishTransaction:允許您從支付隊列中移除交易。

我想我會問我的IAP引擎檢查應用程序退出時是否有任何IAP正在處理(當用戶在下載時停止應用程序時發生問題),如果是,則調用finishTransaction :.

希望它有幫助。