在保存到照片卷之前为视频文件指定特定名称-iOS
我正在开发一个iOS应用程序,最近我在一个popover中实现了一个imagePicker,允许用户录制照片和视频。我想把它们存储在iPad的照片卷中,这样用户以后可以在iTunes中同步它们。我已经能够成功地做到这一点,但我想给每张照片和视频一个唯一的名称,其中包含有关照片和视频的有用信息,以便我以后可以加载它们。具体地说,我想使用类的属性live\u-trial\u-id作为文件名来存储照片。下面是我当前用于将照片和视频存储到照片卷的代码。我知道我可以用图片的元数据来实现这一点,但对于视频,我迷失了方向。提前感谢您对此问题的帮助在保存到照片卷之前为视频文件指定特定名称-iOS,ios,video,photo,Ios,Video,Photo,我正在开发一个iOS应用程序,最近我在一个popover中实现了一个imagePicker,允许用户录制照片和视频。我想把它们存储在iPad的照片卷中,这样用户以后可以在iTunes中同步它们。我已经能够成功地做到这一点,但我想给每张照片和视频一个唯一的名称,其中包含有关照片和视频的有用信息,以便我以后可以加载它们。具体地说,我想使用类的属性live\u-trial\u-id作为文件名来存储照片。下面是我当前用于将照片和视频存储到照片卷的代码。我知道我可以用图片的元数据来实现这一点,但对于视频,
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
UIImage *originalImage, *editedImage, *imageToSave;
// Handle a still image capture
if( [mediaType isEqualToString:@"public.image"]){
editedImage = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerOriginalImage];
if (editedImage) {
imageToSave = editedImage;
} else {
imageToSave = originalImage;
}
// Get the image metadata
UIImagePickerControllerSourceType pickerType = picker.sourceType;
if(pickerType == UIImagePickerControllerSourceTypeCamera)
{
NSDictionary *imageMetadata = [info objectForKey:
UIImagePickerControllerMediaMetadata];
// Get the assets library
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
ALAssetsLibraryWriteImageCompletionBlock imageWriteCompletionBlock =
^(NSURL *newURL, NSError *error) {
if (error) {
NSLog( @"Error writing image with metadata to Photo Library: %@", error );
} else {
NSLog( @"Wrote image with metadata to Photo Library");
}
};
// Save the new image (original or edited) to the Camera Roll
[library writeImageToSavedPhotosAlbum:[imageToSave CGImage]
metadata:imageMetadata
completionBlock:imageWriteCompletionBlock];
}
}
if ([mediaType isEqualToString:@"public.movie"]) {
UIImagePickerControllerSourceType pickerType = picker.sourceType;
if(pickerType == UIImagePickerControllerSourceTypeCamera)
{
NSURL *mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
// Get the assets library
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
ALAssetsLibraryWriteVideoCompletionBlock videoWriteCompletionBlock =
^(NSURL *newURL, NSError *error) {
if (error) {
NSLog( @"Error writing image with metadata to Photo Library: %@", error );
} else {
NSLog( @"Wrote image with metadata to Photo Library");
}
};
// Save the new image (original or edited) to the Camera Roll
[library writeVideoAtPathToSavedPhotosAlbum:mediaURL
completionBlock:videoWriteCompletionBlock];
}
}
我还希望尽可能避免创建自定义库或自定义元数据。我真的只是想在上传照片的过程中更改文件名,结果我回答了自己的问题。我想做的是保存到应用程序的文档目录,而不是照片卷。这使我能够访问已保存的文件,并在以后连接时将其同步到计算机 我最后回答了自己的问题。我想做的是保存到应用程序的文档目录,而不是照片卷。这使我能够访问已保存的文件,并在以后连接时将其同步到计算机 感谢您的代码帮助我识别正在捕获的视频或图像;-)感谢您的代码帮助我识别正在捕获的视频或图像;-)