- 技术问题发到问答:我知道,我仍旧要在论坛继续发布问题
大大们,我用ALAssetsLibrary把照片库里的照片copy到app的Documents下面,总是到一百多张后就出现内存警告,然后crash,请帮忙看看是哪里的问题,不胜感激!!!dispatch_async
(dispatch_get_global_queue
(0, 0), ^{NSAutoreleasePool
*pool = [[NSAutoreleasePool
alloc] init]; [pool
release];
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
]) {//
把image copy
到Documents/DMS/Photo
文件夹下面 ALAssetRepresentation *rep = [result
defaultRepresentation];
CGImageRef iref = [rep
fullScreenImage];
NSString *tt = [rep
filename];
if (iref) {
UIImage *image = [[
UIImage alloc]
init];
image = [
UIImage imageWithCGImage:iref];
NSData *imageData = [[
NSData alloc]
init];
imageData =
UIImagePNGRepresentation(image);
if(image==
nil){
NSLog(@"---------------------the imageData is nil"
); }
else{
NSString *fullPath = [pathPhoto
stringByAppendingFormat:
@"/%@.png",tt];
NSLog(
@"fullPath================%@",fullPath);
if (![[
NSFileManager defaultManager]
fileExistsAtPath:fullPath]){
[[
NSFileManager defaultManager]
createFileAtPath:fullPath
contents:imageData
attributes:
nil];
NSLog(@"Creat image file fullPath================%@"
,fullPath); }
}
[image
release];
[imageData
release];
}
}
};
ALAssetsLibraryGroupsEnumerationResultsBlock
libraryGroupsEnumeration = ^(
ALAssetsGroup* group,
BOOL* stop){
if (group ==
nil)
{
return;
}
if (group!=
nil) {
[group
enumerateAssetsUsingBlock:groupEnumerAtion];
}
NSLog(@"finish--------------------------------------------"
);//NSLog(@"photoUrlListArray=========%@",photoUrlListArray);
//[self performSelectorOnMainThread:@selector(exportPhotoUrls:) withObject:nil waitUntilDone:YES];
//[photoUrlListArray release];
return;
};
ALAssetsLibrary* library = [[
ALAssetsLibrary alloc]
init];
[library enumerateGroupsWithTypes
:ALAssetsGroupSavedPhotos
usingBlock:libraryGroupsEnumeration
failureBlock:failureblock];
[library
release];
});