2012-03-16 69 views
2

我有一個iPad應用程序,可從後端下載視頻,圖像和PDF,但過了一會兒(400 MB下載後)應用程序崩潰,控制檯將我打印回gdb。 Down將應用程序下載到設備時,iPad應用程序崩潰

這裏是我用於視頻文件的寫入功能的一部分。

UPDATE

的應用程序做下載的所有文件,如果我釋放NSData對象「mediaDataResponse」,但下載的所有文件後,給了我一個EXC_BAD_ACCES錯誤。

任何幫助?

   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
       NSString *docsPath = [paths objectAtIndex:0]; 
       NSString *imageCacheDirPath = [docsPath stringByAppendingPathComponent:@"video"]; 

       if (![[NSFileManager defaultManager] fileExistsAtPath:imageCacheDirPath]) 
       { 
        [[NSFileManager defaultManager] createDirectoryAtPath:imageCacheDirPath 
               withIntermediateDirectories:NO 
                   attributes:nil 
                    error:NULL]; 
       } 

       NSString *filename = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/video/%@.%@",cacheFileName,extensionstring]]; 
       [mediaDataResponse writeToFile:filename options: NSDataWritingAtomic error: &error]; 

       //Thumbnail 
       NSArray *thumbpaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
       NSString *thumbdocsPath = [thumbpaths objectAtIndex:0]; 
       NSString *thumbimageCacheDirPath = [thumbdocsPath stringByAppendingPathComponent:@"thumbnail"]; 

       if (![[NSFileManager defaultManager] fileExistsAtPath:thumbimageCacheDirPath]) 
       { 
        [[NSFileManager defaultManager] createDirectoryAtPath:thumbimageCacheDirPath 
               withIntermediateDirectories:NO 
                   attributes:nil 
                    error:NULL]; 
       } 

       NSURL *thumburl = [NSURL URLWithString:media.mediaThumbnail]; 
       NSData *thumburlData = [NSData dataWithContentsOfURL:thumburl]; 

       NSString *thumbfilename = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/thumbnail/%@.jpg", thumbcacheFileName]]; 
       [thumburlData writeToFile:thumbfilename options: NSDataWritingAtomic error: &error]; 

      } 

當您在應用程序崩潰後啓動應用程序時,它會繼續停止下載。任何人都有同樣的問題?提前致謝。

+0

你能提供關於崩潰報告的詳細信息嗎? – tarmes 2012-03-16 08:21:35

+0

讓我檢查一下我是否可以找到崩潰報告的更多細節。 – Ryan 2012-03-16 08:44:54

+0

也是一個細節。我在下載文件時遇到此錯誤。 「SendDelegateMessage(NSInvocation *):委託(_selectionLayoutChangedByScrolling :)在等待10秒後失敗返回主運行循環模式:_kCFURLConnectionPrivateRunLoopMode」也許這與問題有關。 – Ryan 2012-03-16 08:46:22

回答

2

我想你可能會試圖加載所有400MB的文件到內存中(基於NSData的使用),這可能不是正確的方式去(並通過您的LowMemory評論證實)。您可能希望擁有自己的NSURLConnection委託,該委託在接收到響應時打開文件,並將所有字節直接附加到該文件(不保留在NSData中)。

+0

我已經試圖建立這樣的事情,我會試試這個!感謝你的回答! – Ryan 2012-03-19 14:18:23

相關問題