4

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

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)
 {

 }];
4

1 回答 1

3
-(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 并设置新标题。

于 2015-11-25T05:58:32.940 回答