1

I have a request, for a photo to be saved in an album with a file name.

I can't find a code online that I can refer to.

Send an image called "ABC.jpg" to the iPad via AirDrop on your Mac, On iPad, this image is exported as "ABC.jpg", not "IMG_xxx.jpg".

This means that the image can be named, is there a way to rename the image?

Thank you so much for your answer.

[[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{

        PHAssetCollection *assetCollection = [self customAlbumForTitle:self->albumFolderName];

        PHAssetCollectionChangeRequest *assetCollectionChangRequest;
        if (assetCollection) {
            assetCollectionChangRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:assetCollection];
        } else {
            assetCollectionChangRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:self->albumFolderName];
        }


        PHAssetChangeRequest *assetChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:theImage];


        PHObjectPlaceholder *assetPlaceholder = [assetChangeRequest placeholderForCreatedAsset];
        [assetCollectionChangRequest addAssets:@[assetPlaceholder]];

    } error:&err];
xylisten
  • 11
  • 3
  • Photos in the photo library have no "name", so what is the question even about? – matt May 08 '20 at 01:41
  • When exporting photos from an album to a Mac or email it will have a file name, for example:IMG_xxxx.jpg – xylisten May 08 '20 at 03:40
  • Sure, a file has a name; when your app exports a photo as a file, now it is a file and your app can give it a name too. But as long as the asset belongs to the photo library it is not a file and it has no name intrinsically. – matt May 08 '20 at 03:56
  • I'm sorry, can I ask a question? Send an image called "ABC.jpg" to the iPad via AirDrop on your Mac, On iPad, this image is exported as "ABC.jpg", not "IMG_xxx.jpg". – xylisten May 08 '20 at 05:11
  • This means that the image can be named, is there a way to rename the image? – xylisten May 08 '20 at 05:12
  • If _you_ send the image, you get to name it. But if you ask the Photos app to send the image, it gets to name the file and you cannot affect the name beyond what was discussed in the linked duplicate. – matt May 08 '20 at 12:49
  • I'm looking for the workaround as well, and seems that it indeed cannot be edited (at least now). I found that metadata like "name" is stored in a PHAssetResource instance (_"an underlying data resource associated with a photo, video, or Live Photo asset in the Photos library"_), and its `originalFilename` is readonly. However, if renaming photo name is what u must do in ur project, u can try to create a photo copy w/ desired name, and delete old one. – Kjuly Mar 03 '21 at 23:54

0 Answers0