ios8中,addAssetsGroupAlbumWithName 相册创建后手动删除,不能再进行创建显示

// Add a new ALAssetsGroup to the library.

// The name of the ALAssetsGroup is name and the type is ALAssetsGroupAlbum.  The editable property of this ALAssetsGroup returns YES.

// If name conflicts with another ALAssetsGroup with the same name, then the group is not created and the result block returns a nil group.

// When the ALAssetsGroup is added, the user may be asked to confirm the application's access to the data.  If the user denies access to the application or if no application is allowed to access the data, the failure block will be called.

// If the data is currently unavailable, the failure block will be called.

 

[_library addAssetsGroupAlbumWithName:@"Test" resultBlock:^(ALAssetsGroup *group) {

//手动删除相册后,返回的group为nil,从上面的注释文档可以得到,添加的相册名称发生冲突。

} failureBlock:^(NSError *error) {

        NSLog(@"error : %@",error);

    }];

可能的原因: iOS 8.0 之后, 相册新增了 Recently Deleted (最近删除) 这个功能,默认30天后自动删除照片, 可能我们删除的相册并没有完全删除, 导致创建相册虽然成功, 但却为 nil ,因为创建的相册还是处于 Recently Deleted 的状态;

解决之道:

(在 iOS 8.0 后, 使用the Photos framework 代替 the Assets Library framework , The Photos framework 提供更特色和更好的表现 在使用 photo library 工作的时候)

苹果官方Photo Framework例子:

https://developer.apple.com/devcenter/download.action?path=/wwdc_2014/wwdc_2014_sample_code/exampleappusingphotosframework.zip

仔细挖掘下然后就能解决啦~

iOS 8.0+ 使用Photos framework 创建相册代码

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
{
  [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"Test"];
} completionHandler:^(BOOL success, NSError *error) 
{
  if (!success) {
    NSLog(@"Error creating album: %@", error);
  }
}];

 

posted on 2016-08-09 10:42  codemaker313  阅读(205)  评论(0编辑  收藏  举报

导航