gpt4 book ai didi

objective-c - 如何编辑或重命名 PHAssetCollection LocalizedTitle?

转载 作者:行者123 更新时间:2023-12-04 12:50:16 25 4
gpt4 key购买 nike

我想在我的应用程序中更改专辑名称。

if ([collection canPerformEditOperation:PHCollectionEditOperationRename]  == YES)
{
//rename localizedTitle
}

如果那是"is",我想更改名称。

我的代码是:
PHFetchOptions *userAlbumsOptions = [PHFetchOptions new];
userAlbumsOptions.predicate = [NSPredicate predicateWithFormat:@"estimatedAssetCount > 0"];

PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:userAlbumsOptions];

[userAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL *stop)
{

}];

最佳答案

-(void)changeAlbumtitle:(PHAssetCollection *)collection withTitle:(NSString *)title {

if (![collection canPerformEditOperation:PHCollectionEditOperationRename]) {

NSLog(@"can't PerformEditOperation");
return;
}


[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCollectionChangeRequest *changeTitlerequest =[PHAssetCollectionChangeRequest changeRequestForAssetCollection:collection];
changeTitlerequest.title = title;


} completionHandler:^(BOOL success, NSError *error) {
NSLog(@"Finished editing collection. %@", (success ? @"Successfully." : error));
}];


}

在上面给出函数传递专辑对象(PHAssetCollection)和标题
  • 首先函数检查PHAssetCollection可以进行rename
    编辑操作
  • 如果可以进行编辑操作,则实现 PHAssetCollectionChangeRequest 并设置新标题。
  • 关于objective-c - 如何编辑或重命名 PHAssetCollection LocalizedTitle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31239513/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com