iOS 앱에서 작업 중이며 최근에 사용자가 사진과 동영상을 녹화 할 수있는 popover에 imagePicker를 구현했습니다. 나중에 iPad에서 사진을 동기화 할 수 있도록 iPad의 사진 롤에 저장하고 싶습니다. 나는이 작업을 성공적으로 수행 할 수 있었지만 사진과 비디오에 대한 유용한 정보가 포함 된 고유 한 이름을 각 사진과 비디오에 제공하여 나중에로드 할 수 있습니다. 특히, live_trial_id 클래스의 속성을 파일 이름으로 사용하여 사진을 저장하고 싶습니다. 아래는 사진과 비디오를 사진 롤에 저장하는 데 현재 사용하고있는 코드입니다. 나는 그림을위한 메타 데이터로 이것을 할 수 있지만, 나는 잃어버린 비디오를 이해할 수있다. 이 문제에 대한 도움에 미리 감사드립니다!사진 파일로 저장하기 전에 동영상 파일에 특정 이름을 지정하십시오. - iOS
-(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];
}
}
가능한 경우 사용자 지정 라이브러리 또는 사용자 지정 메타 데이터를 만드는 것을 피하고 싶습니다. 나는 방금 사진 롤로가는 길에 파일 이름을 바꾸고 싶었다.
감사 코드 내 비디오 또는 캡처 된 이미지 사이의 식별을 도왔습니다 ;-) –