次のコードを使用して、アセットライブラリから画像をロードしています。それは機能していません。displayImage uiimageviewer をクリックすると、所有する ALAssetsLibrary の存続期間を過ぎて無効なアクセス試行が表示されます。
ヘッダー ファイル
#import <UIKit/UIKit.h>
#import "BFCropInterface.h"
#import "GRKImage.h"
#import <AssetsLibrary/AssetsLibrary.h>
@interface BFViewController : UIViewController{
GRKImage *gImg;
}
@property (nonatomic, strong) IBOutlet UIImageView *displayImage;
@property (nonatomic, strong) UIImage *originalImage;
@property (nonatomic, strong) BFCropInterface *cropper;
@property (nonatomic, retain) GRKImage *gImg;
@property (strong, atomic) ALAssetsLibrary* library;
- (IBAction)cropPressed:(id)sender;
- (IBAction)originalPressed:(id)sender;
- (IBAction)savePressed:(id)sender;
@end
メインファイル:viewDidload内
if ( [[self.gImg.URL absoluteString] hasPrefix:@"assets-library://"] ){
typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
float scale=[rep scale];
ALAssetOrientation orientation=[rep orientation];
if (iref){
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *originalImage = [UIImage imageWithCGImage:iref scale:scale orientation:(UIImageOrientation)orientation];
self.displayImage.contentMode = UIViewContentModeScaleAspectFit;
[self.displayImage setImage:originalImage];
});
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){
//failed to get image.
};
self.library = [[ALAssetsLibrary alloc] init];
[self.library assetForURL:self.gImg.URL resultBlock:resultblock failureBlock:failureblock];
}