首页 > 代码库 > UIImagePickerController获取图片名

UIImagePickerController获取图片名

//创建

UIImagePickerController *imagePick = [[UIImagePickerControlleralloc] init];

        imagePick.delegate =self;

        imagePick.allowsEditing =YES;

        imagePick.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;

        imagePick.mediaTypes=[NSArrayarrayWithObject:@"public.image"];

[selfpresentViewController:imagePickanimated:animated completion:completion];




只需实现代理方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

    // get the ref url

    NSURL *assetURL = [infoobjectForKey:UIImagePickerControllerReferenceURL];

    ALAssetsLibrary *library = [[ALAssetsLibraryalloc] init];

    [libraryassetForURL:assetURL resultBlock:^(ALAsset *asset) {

       ALAssetRepresentation *imageRep = [asset defaultRepresentation];

        NSLog(@"[imageRep filename] : %@", [imageRepurl]);

        NSLog(@"[imageRep filename] : %@", [imageRepfilename]);

        

    }failureBlock:^(NSError *error) {

        

    }];

}