獲取系統相簿以及獲取圖片的檔名
阿新 • • 發佈:2019-01-22
選擇系統相簿圖片之後顯示其檔名字
//選擇圖片的時候呼叫 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage]; if (img != nil) { //獲取圖片的名字 __block NSString *imageFileName; NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL]; ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) { ALAssetRepresentation *representation = [myasset defaultRepresentation]; imageFileName = [representation filename]; NSLog(@"imageFileName : %@",imageFileName); //檔名字 v_cert.lbl_file.text = imageFileName; }; ALAssetsLibrary *assetslibrary = [[ALAssetsLibrary alloc] init]; [assetslibrary assetForURL:imageURL resultBlock:resultblock failureBlock:nil]; } //設定上傳的圖片 v_cert.img_file.image = img; [picker dismissViewControllerAnimated:YES completion:nil]; }