1. 程式人生 > >UIImagePickerController獲取圖片詳細資訊

UIImagePickerController獲取圖片詳細資訊

透過UIImagePickerController,獲取圖片名字、唯一標示UTI、路徑url

NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
[self getImageDetailInfo:imageURL];
//獲取圖片的詳細資訊
-(void)getImageDetailInfo:(NSURL*)imageUrl{
    __block NSString* imageFileName;
    ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
    [assetslibrary assetForURL:imageUrl
                   resultBlock:^(ALAsset *myasset){
                       ALAssetRepresentation *representation = [myasset defaultRepresentation];
                       imageFileName = [representation filename];
                       NSLog(@"圖片路徑名:%@",imageFileName);
                       NSLog(@"圖片UTI:%@",[representation UTI]);
                       NSLog(@"圖片URL:%@",[representation url]);
                   }
                  failureBlock:nil];
}