iOS_给保存到系统相册的视频添加位置信息
来源:互联网 发布:pl sql删除存储过程 编辑:程序博客网 时间:2024/06/18 11:29
录制结束后的视频要保存到系统相册,之前是不带位置信息的,现在要实现把视频保存到系统相册时添加上位置信息
直接上代码:
#pragma mark - 给视频添加GPS- (void)saveVideoToSystemAlbumWithPath:(NSString *)videoPath{ ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init]; [library writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:videoPath] completionBlock:^(NSURL *assetURL, NSError *error) { if (error) { NSLog(@"Save video to system Album failed:%@",error); }else{ [self addGPSToSavedVideo]; NSLog(@"Save video to system album success!"); } }];}- (void)addGPSToSavedVideo{ //支持ios8以上的版本 if ([PHAsset class]){ // 获取相册里所有的视频,并按视频的创建时间排序 PHFetchOptions *fetchOptions = [[PHFetchOptions alloc]init]; fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; fetchOptions.fetchLimit = 1; PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:fetchOptions]; // 拿到最后一个视频资源 即最新的视频资源 PHAsset *lastAsset = [fetchResult lastObject]; [[PHImageManager defaultManager] requestImageForAsset:lastAsset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:nil resultHandler:^(UIImage *result, NSDictionary *info){ if ([info objectForKey:PHImageErrorKey] == nil && ![[info objectForKey:PHImageResultIsDegradedKey] boolValue]) { NSArray *resources = [PHAssetResource assetResourcesForAsset:lastAsset]; NSString *orgFilename = ((PHAssetResource*)resources[0]).originalFilename; //我们一旦拿到asset,就可以看到metadata信息 [lastAsset requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) { NSURL *imageURL = contentEditingInput.fullSizeImageURL; NSString *urlstring = [imageURL absoluteString]; NSLog(@"Urlstring = %@",urlstring); }]; //用坐标和日期创建新的location double latitude = [TVULocalManager getLatitude]; double longitude = [TVULocalManager getLongitude]; CLLocationCoordinate2D locationNew = CLLocationCoordinate2DMake(latitude,longitude); NSDate *nowDate = [NSDate date]; CLLocation *newLocation = [[CLLocation alloc ]initWithCoordinate:locationNew altitude:0.0 horizontalAccuracy:1.0 verticalAccuracy:1.0 timestamp:nowDate]; //我们请求更改metadata,并插入新的location //当视频已经被保存的回调被触发时,将会把写的元数据写入视频 [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ // 从要被修改元数据的Asset中创建修改请求 PHAssetChangeRequest *request = [PHAssetChangeRequest changeRequestForAsset:lastAsset]; // 设置请求的属性来改变Asset request.location = newLocation; } completionHandler:^(BOOL success, NSError *error) { NSLog(@"Finished updating asset. %@", (success ? @"Success." : error)); }]; } }]; }else { //如果是iOS8之前的版本 暂时不支持添加位置信息 NSLog(@"Pre-iOS8 does not support adding GPS"); }}zhu【注】要记得添加头文件
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>
阅读全文
0 0
- iOS_给保存到系统相册的视频添加位置信息
- 保存视频文件到相册视频的时长为0
- 保存图片到系统相册
- 保存图片到系统相册
- 保存GIF到系统相册
- 保存图片到系统相册
- iOS从相册选择视频和保存视频到相册
- 保存视频到自定义位置
- 【学习ios之路:UI系列】获取通过UIImagePackerController获取的系统相册图片的名称信息及保存系统相册到本地
- 保存照片和视频到相册显示
- 照片保存到相册,并添加到自定义相册中
- 将图片保存到系统相册的两种方法
- 将图片保存到系统相册的两种方法
- Android 保存应用的图片到系统相册中
- 调用系统相机录像,压缩保存到相册(附仿微信视频录制demo)
- Swift - 视频录制教程1(调用摄像头录像,并保存到系统相册)
- 【系统相册】Android 保存图片到系统相册
- 保存图片/视频到相册 保存完成后通知事件
- CSU
- IntelliJ IDEA 使用心得与常用快捷键
- 组合框的全选、全不选以及反选问题
- Selenium 调用IEDriverServer打开IE浏览器
- QT Linux
- iOS_给保存到系统相册的视频添加位置信息
- Java基础知识(二)
- 基于ubuntu搭建Redis(4.0) Cluster 高可用(HA)集群环境
- 欢迎使用CSDN-markdown编辑器
- CSS设置水平居中、垂直居中
- 排序四:堆排序
- SurfaceView
- 最新本Sublime使用
- mysql查询今天、昨天、7天、近30天、本月、上一月 数据