imagePickerControl で選択した画像を取得し、提供された URL を使用して開き、imageview に表示しようとしています。UIImagePickerControllerOriginalImage を使用して画像を設定すると正常に動作しますが、画像をデータベースに保存するのではなく、URL を保存したいだけです。これをコードにさらに拡張する前に、それが機能することを確認したかったのです。以下は、選択された画像を PickerController から返し、画像を表示しようとするコードです。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
self.imageURL=[info objectForKey:UIImagePickerControllerReferenceURL];
CCLog(@"Image =%@",[info objectForKey:UIImagePickerControllerReferenceURL]);
// self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
switch(status){
case ALAuthorizationStatusDenied: {
CCLog(@"not authorized");
break;
}
case ALAuthorizationStatusRestricted: {
CCLog(@"Restricted");
break;
}
case ALAuthorizationStatusNotDetermined: {
CCLog(@"Undetermined");
break;
}
case ALAuthorizationStatusAuthorized: {
CCLog(@"Authorized");
CCLog(@"self.imageURL=%@",self.imageURL);
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
__block UIImage *returnValue = nil;
[library assetForURL:self.imageURL resultBlock:^(ALAsset *asset) {
returnValue = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
} failureBlock:^(NSError *error) {
NSLog(@"error : %@", error);
}];
[self.imageDisplay setImage:returnValue];
[self.imageDisplay setNeedsDisplay];
break;
}
default: {
CCLog(@"Unknown hit default");
break;
}
}
// You have the image. You can use this to present the image in the next view like you require in `#3`.
}
これを実行すると、トレースするとreturnValueがnilになり、画像が表示されません。https://stackoverflow.com/a/13276649/3723298からコードを取得しました
ありがとう