首页 > 代码库 > 照片保存到相册,并添加到自定义相册中
照片保存到相册,并添加到自定义相册中
-(void)addAssetURL:(NSURL*)assetURL toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock { //相册存在标示 __block BOOL albumWasFound = NO; ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init]; //search all photo albums in the library [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop) { //判断相册是否存在 if ([albumName compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame) { //存在 albumWasFound = YES; //get a hold of the photo's asset instance [assetsLibrary assetForURL: assetURL resultBlock:^(ALAsset *asset) { //add photo to the target album [group addAsset: asset]; //run the completion block completionBlock(nil); } failureBlock: completionBlock]; return; } //如果不存在该相册创建 if (group==nil && albumWasFound==NO) { __weak ALAssetsLibrary* weakSelf = assetsLibrary; //创建相册 [assetsLibrary addAssetsGroupAlbumWithName:albumName resultBlock:^(ALAssetsGroup *group) { //get the photo's instance [weakSelf assetForURL: assetURL resultBlock:^(ALAsset *asset) { //add photo to the newly created album [group addAsset: asset]; //call the completion block completionBlock(nil); } failureBlock: completionBlock]; } failureBlock: completionBlock]; return; } }failureBlock:completionBlock]; }
代码来着QQ群群友分享,感谢分享~
照片保存到相册,并添加到自定义相册中
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。