我用这段代码获取相册图片,并在文档中创建文件,但是会出现Received memory warning,然后crash。</p>
这是我使用的代码。谁能告诉我我做错了什么?
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){
NSLog(@"error occour =%@", [myerror localizedDescription]);
};
ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if (result!=NULL) {
//we can get all the things in the defaultRepresentation such as size info in UTI
}
//just fetching photos
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
//copy image to the path:Documents/DMS/Photo
ALAssetRepresentation *rep = [result defaultRepresentation];
NSString *tt = [rep filename];
NSString *fullPath = [pathPhoto stringByAppendingFormat:@"/%@",tt];
if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]){
UIImage *image = [[UIImage alloc]initWithCGImage:[rep fullScreenImage]];
NSData *imageData = UIImagePNGRepresentation(image);
[image release];
[[NSFileManager defaultManager] createFileAtPath:fullPath contents:imageData attributes:nil];
NSLog(@"Creat image file fullPath================%@",fullPath);
//imageData = nil;
[imageData release];
}else{
NSLog(@"---------------------the image is Exist");
}
}
};
ALAssetsLibraryGroupsEnumerationResultsBlock
libraryGroupsEnumeration = ^(ALAssetsGroup* group, BOOL* stop){
if (group == nil)
{
return;
}
if (group!=nil) {
[group enumerateAssetsUsingBlock:groupEnumerAtion];
}
NSLog(@"finish--------------------------------------------");
return;
};
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:libraryGroupsEnumeration
failureBlock:failureblock];
[library release];
[池释放];