Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios didFinishPickingMediaWithInfo获取图像文件名_Ios_Iphone_Objective C_Ipad - Fatal编程技术网

Ios didFinishPickingMediaWithInfo获取图像文件名

Ios didFinishPickingMediaWithInfo获取图像文件名,ios,iphone,objective-c,ipad,Ios,Iphone,Objective C,Ipad,我正在尝试从相机获取图像文件名。我看过很多关于使用UIImagePickerControllerReferenceURL或UIImagePickerControllerMediaURL检索文件名的帖子,但这只能得到一个类似于:://asset/asset.JPG?id=D1D715A8-6956-49FF-AF07-CE60FE93AE32&ext=JPG的文件名。我相信这是因为图像还没有保存,因此像img001.jpg这样的名称在中不可用 有人知道如何获取文件名吗?我正在起诉,我需要在UIIm

我正在尝试从相机获取图像文件名。我看过很多关于使用UIImagePickerControllerReferenceURL或UIImagePickerControllerMediaURL检索文件名的帖子,但这只能得到一个类似于:://asset/asset.JPG?id=D1D715A8-6956-49FF-AF07-CE60FE93AE32&ext=JPG的文件名。我相信这是因为图像还没有保存,因此像img001.jpg这样的名称在中不可用

有人知道如何获取文件名吗?我正在起诉,我需要在UIImageWriteToSavedPhotosAlbum之后做这件事,但我似乎无法理解

这个问题我已经问过很多次了,但似乎没有人能“真正”回答,他们只是给出了从选取者而不是相机中选择的图像的文件名

谢谢你的帮助

**更新:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self.popoverController dismissPopoverAnimated:true];

    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    [self dismissViewControllerAnimated:YES completion:nil];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
    {
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        imageView.image = image;
        if (newMedia)
        {
            UIImageWriteToSavedPhotosAlbum(image,
                                           self,
                                           @selector(image:finishedSavingWithError:contextInfo:),
                                           nil);

            NSURL *refURL = [info valueForKey:UIImagePickerControllerMediaURL];

            // define the block to call when we get the asset based on the url (below)
            ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
            {
                ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
                NSLog(@"[imageRep filename] : %@", [imageRep filename]);
            };
            // get the asset library and fetch the asset based on the ref url (pass in block above)
            ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
            [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
        }
    }
}

上面是我的代码,但当记录imageRep文件名时,它是空的。

您是否能够获取资产??是的,我获取了资产,但它不包含文件名,它只包含asset.jpg。我相信这是因为图像尚未保存。我将用我的代码更新我的帖子,不确定这是否有用,但你永远不知道。嗯,是的,你是对的,你有没有尝试获取最后保存的照片名称??然后你可以创建下一张图片的名称…你试过将资产代码移动到完成回调中吗?对不起,我没有意识到我激活了大写字母