2011-08-08 13 views
0

現在、インターネットから雑誌のコンテンツをダウンロードするiPhoneマガジンアプリケーションに取り組んでいます。雑誌のページはイメージフォーマットであり、約120ページあります。NSThread iPhoneを使用して100枚の画像をダウンロード中にクラッシュする

これは私の問題解決の方法です。

- (void) downloadDergiPages { 

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

NSArray *resourcePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [resourcePaths objectAtIndex:0]; 
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Dergilerim"]; 
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:indirilenSayi]; 


for (int i=1; i<=numberOfPages; i++) { 

    NSString *url = [NSString stringWithFormat:@"%@getdergipage?dergikey=%@&page=%d", [RepositoryInfo getHostName], indirilenDergi, i]; 
    NSLog(@"%@", url); 

    NSData *receivedData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]]; 

    NSString *path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.png",i]]; 
    [receivedData writeToFile:path atomically:YES]; 
    [receivedData release]; 

    [self performSelectorOnMainThread:@selector(updateProgress:) withObject:[NSNumber numberWithInt:i] waitUntilDone:YES]; 
} 


[self performSelectorOnMainThread:@selector(removePopupView) withObject:nil waitUntilDone:YES]; 
//[self removePopupView]; 

[pool release]; 
} 

このコードフラグメントは問題なくiPadのアプリケーションで動作しますが、それはアプリがiPhoneでの第44回 ページのダウンロードの終了後にクラッシュします。これは、ログコンソールから私が理解しているように、メモリの問題が原因です。 イメージを取得し、ディスクに1つずつ保存するだけです。私はすべての割り当て "receivedData"を解放しています。 このコードで何が問題になる可能性があり、どのように機能させることができますか?

ありがとうございます。

答えて

1

ダウンロード用にASIHTTPRequest APIを使用してください。

0

あなたはディスクに使用すると、デリゲートのメソッドを介してそれを受け取るたびに、データのチャンクを保存することでNSURLConnection

を使用する必要があります。接続:didReceiveData: