このコードを使用してアルバムの写真を取得し、ドキュメントにファイルを作成しましたが、Received memory の警告が表示されてクラッシュします。</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];
[プール解放];