我目前正在从iPhone上下载杂志内容的iPhone杂志应用程序。杂志页面为图片格式,大约有120页。使用NSThread下载100张图像时发生崩溃iPhone
这是我对问题的解决方案。
- (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 页面下载终了后的崩溃。这是因为我从日志控制台了解到的内存问题。 我只想获取图像并逐个保存到磁盘。我释放所有分配“receivedData”。 这段代码可能存在什么问题,我该如何让它工作?
预先感谢您..