iPhone カメラロールのカスタム アルバムに画像を保存できます。たとえば、アルバム名を「Fun」にすると、撮影したすべての画像がそのフォルダーに保存されます。ここで、私が望むことを達成するのに非常にうまく機能するヘルパークラスに出会いました。
ただし、私が使用している方法では動画をカスタム フォルダーに保存しませんが、フォルダーが作成されます。そこに保存しようとしている動画は空です。私はそれをデバッグしようとしましたが、進歩はありませんでした。その方法はここにあります:
-(void)addAssetURL:(NSURL*)assetURL toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
__block BOOL albumWasFound = NO;
//search all photo albums in the library
[self enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
//compare the names of the albums
if ([albumName compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame) {
//target album is found
albumWasFound = YES;
NSData *data = [NSData dataWithContentsOfURL:assetURL];
if ([data length] > 0) {
//get a hold of the photo's asset instance
[self assetForURL: assetURL
resultBlock:^(ALAsset *asset) {
[group addAsset: asset];
//run the completion block
completionBlock(nil);
} failureBlock: completionBlock];
}
//album was found, bail out of the method
return;
}
if (group==nil && albumWasFound==NO) {
//photo albums are over, target album does not exist, thus create it
__weak ALAssetsLibrary* weakSelf = self;
//create new assets album
[self addAssetsGroupAlbumWithName:albumName
resultBlock:^(ALAssetsGroup *group) {
//get the photo's instance
[weakSelf assetForURL: assetURL
resultBlock:^(ALAsset *asset) {
NSLog(@"asset: %@",asset);
//add photo to the newly created album
[group addAsset: asset];
//call the completion block
completionBlock(nil);
} failureBlock: completionBlock];
} failureBlock: completionBlock];
//should be the last iteration anyway, but just in case
return;
}
} failureBlock: completionBlock];
}
ビデオをフォト ライブラリのカスタム アルバムに保存する適切な方法を知っている人はいますか?