如何编辑或重命名 PHAssetCollection LocalizedTitle?
Posted
技术标签:
【中文标题】如何编辑或重命名 PHAssetCollection LocalizedTitle?【英文标题】:How can I edit or rename a PHAssetCollection LocalizedTitle? 【发布时间】:2015-07-06 07:00:43 【问题描述】:我想在我的应用中更改专辑名称。
if ([collection canPerformEditOperation:PHCollectionEditOperationRename] == YES)
//rename localizedTitle
如果是“是”,我想更改名称。
我的代码是:
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)
];
【问题讨论】:
【参考方案1】:-(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 可以执行重命名的函数 编辑操作
如果可以进行编辑操作,则执行 PHAssetCollectionChangeRequest 并设置新标题。
【讨论】:
以上是关于如何编辑或重命名 PHAssetCollection LocalizedTitle?的主要内容,如果未能解决你的问题,请参考以下文章