如何编辑或重命名PHAssetCollection LocalizedTitle?

时间:2015-07-06 07:00:43

标签: objective-c xcode phasset phphotolibrary

我想在我的应用中更改albumName。

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 个答案:

答案 0 :(得分: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可以执行重命名 editOperation

  • 如果可以进行编辑操作,则实施PHAssetCollectionChangeRequest并设置新标题。