iPod Touch 第 2 世代を使用しており、写真名を使用してアセット ライブラリから写真を取得しようとしています。デバイスで復元を実行して、工場出荷時の 4.1 であることを確認しました。
私のヘッダーファイルには次のものがあります:
#import <AssetsLibrary/AssetsLibrary.h>
{
BOOL fetching;
}
@property BOOL fetching;
typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
私のコードは次のとおりです。
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSArray *array = [info allKeys];
for (NSString *str in array) NSLog(@"Key = %@", str);
// iPad uses UIImagePickerControllerMediaURL
// iPhone uses UIImagePickerControllerReferenceURL
NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
fetching = NO;
NSLog(@"1 fetching = %d", fetching);
[self photoFromURL:url];
NSLog(@"2 fetching = %d", fetching);
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
NSLog(@"3 fetching = %d", fetching);
while (!fetching && [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
NSLog(@"4 fetching = %d", fetching);
...
photoFromURL の場所
- (void) photoFromURL:(NSURL *)inURL
{
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref)
{
photo = [UIImage imageWithCGImage:iref];
[photo retain];
fetching = YES;
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Cannot get image - %@",[myerror localizedDescription]);
};
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary assetForURL:inURL
resultBlock:resultblock
failureBlock:failureblock];
}
これはシミュレーターでは正常に実行されますが、ランループがデバイスに返されることはありません。取得のために最初の 3 つの NSLog ステートメントを通過しましたが、4 番目のステートメントは表示されません。
助けてください。- ダン