Поздний ответ Но я нашел решение проблемы. Проверьте следующий код, для которого я изменил место следующих строк кода, которые вызывали сбой.
ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
albumReadLock = [[NSConditionLock alloc] initWithCondition:0];
// non-busy wait for the asset read to finish (specifically until the condition is "all finished")
[albumReadLock lockWhenCondition:1];
[albumReadLock unlock];
============================== Ниже приведен весь код ======= ==============================
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if(info)
{
// Don't pay any attention if somehow someone picked something besides an image.
if([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeImage]){
// UIImageView *imageView1=[[UIImageView alloc]init]; // = (UIImageView *)self.view;
// Hand on to the asset URL for the picked photo..
self.imageURL = [info objectForKey:UIImagePickerControllerReferenceURL];
// To get an asset library reference we need an instance of the asset library.
static NSConditionLock* albumReadLock;
// sets up a condition lock with "pending reads"
ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
albumReadLock = [[NSConditionLock alloc] initWithCondition:0];
// non-busy wait for the asset read to finish (specifically until the condition is "all finished")
[albumReadLock lockWhenCondition:1];
[albumReadLock unlock];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
NSString *versionWithoutRotation = @"5.0";
BOOL noRotationNeeded = ([versionWithoutRotation compare:osVersion options:NSNumericSearch]
!= NSOrderedDescending);
// The assetForURL: method of the assets library needs a block for success and
// one for failure. The resultsBlock is used for the success case.
ALAssetsLibraryAssetForURLResultBlock resultsBlock = ^(ALAsset *asset)
{
ALAssetRepresentation *representation = [asset defaultRepresentation];
CGImageRef image = [representation fullScreenImage];
if(noRotationNeeded)
{
// Create a UIImage from the full screen image. The full screen image
// is already scaled and oriented properly.
imageView.image = [UIImage imageWithCGImage:image];
}
else
{
// prior to iOS 5.0, the screen image needed to be rotated so
// make sure that the UIImage we create from the CG image has the appropriate
// orientation, based on the EXIF data from the image.
ALAssetOrientation orientation = [representation orientation];
imageView.image = [UIImage imageWithCGImage:image scale:1.0
orientation:(UIImageOrientation)orientation];
}
[albumReadLock lock];
[albumReadLock unlockWithCondition:1];
[picker dismissModalViewControllerAnimated:YES];
};
ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *error)
{
NSLog(@"FAILED! due to error in domain %@ with error code %d", error.domain, error.code);
// This sample will abort since a shipping product MUST do something besides logging a
// message. A real app needs to inform the user appropriately.
[albumReadLock lock];
[albumReadLock unlockWithCondition:1];
[picker dismissModalViewControllerAnimated:YES];
abort();
};
// Get the asset for the asset URL to create a screen image.
[assetsLibrary assetForURL:self.imageURL resultBlock:resultsBlock failureBlock:failureBlock];
// Release the assets library now that we are done with it.
[assetsLibrary release];
}
}
}