// 選択したファイル名を取得する
+ (NSString*)getImageFileName:(UIImagePickerController*)picker pickingMediaInfo:(NSDictionary *)info
{
__block NSString* ret = nil;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
if (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *representation = [myasset defaultRepresentation];
ret = [representation filename];
dispatch_semaphore_signal(semaphore);
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:imageURL
resultBlock:resultblock
failureBlock:nil];
}
});
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
return ret;
}
/*
* 写真アルバムアクセス状況を取得する
*/
// AssetsLibrary.frameworkを組み込む
NSString *message = nil;
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
message = @"カメラを利用できません。";
}
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
switch (status) {
case ALAuthorizationStatusNotDetermined:
message = @"まだ許可ダイアログ出たことない";
break;
case ALAuthorizationStatusRestricted:
message = @"機能制限(ペアレンタルコントロール)で許可されてない";
break;
case ALAuthorizationStatusDenied:
message = @"許可ダイアログで\"いいえ\"が押されています\n"
"設定アプリ -> プライバシー > 写真 -> 該当アプリを\"オン\"する必要があります";
break;
case ALAuthorizationStatusAuthorized:
message = @"写真へのアクセスが許可されています";
break;
default:
break;
}
if (message.length) {
[[[UIAlertView alloc] initWithTitle:@"確認"
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil] show];
}
最終更新:2018年02月02日 13:09