【发布时间】:2011-08-08 12:09:30
【问题描述】:
我目前正在开发一个 iPhone 杂志应用程序,该应用程序从互联网上下载其杂志内容。杂志页面为图片格式,大约有 120 页。
这是我解决问题的方法。
- (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 应用程序中运行没有问题,但它会导致应用程序在 44 号结束后崩溃 在 iPhone 中下载页面。这是因为我从日志控制台了解到的内存问题。 我只想获取图像并一张一张地保存到磁盘。我正在释放所有分配“receivedData”。 这段代码可能有什么问题,我怎样才能让它工作?
提前谢谢你..
【问题讨论】: