我获取了AVURLAsset的URL,如下所示:
NSURL *url = [[asset defaultRepresentation] url];
在控制台中,AVURLAsset的网址如下所示:
资产库://asset/asset.mov ID = A3210417-4BAC-1C78-BD93-4BDD286247D9&安培; EXT = MOV
我尝试从URL获取带扩展名的文件名,如下所示:
NSString *last = [[url URLByDeletingPathExtension] lastPathComponent];
NSString *tnFileName = [NSString stringWithFormat:@"%@_tn.%@", last, url.pathExtension];
这是tnFileName的控制台日志:
tnFileName = asset_tn.mov
如何获得A3210417-4BAC-1C78-BD93-4BDD286247D9部分的字符串?或者资产是否有不同的唯一ID用于缓存资产的静态图像?
为了澄清,我需要将缩略图存储到磁盘,并且我想使用与资产匹配的名称。
答案 0 :(得分:3)
使用这样的字符串:
NSString * urlName = @"assets-library://asset/asset.mov?id=A3210417-4BAC-1C78-BD93-
4BDD286247D9&ext=mov";
NSArray *arr = [urlName componentsSeparatedByString:@"id"];
NSString *str = [arr lastObject];
NSArray *arr1 = [str componentsSeparatedByString:@"&"];
NSLog(@"array is %@",arr1);
NSString *str2 = [[arr1 objectAtIndex:0] substringFromIndex:1];
NSLog(@"str2 is %@",str2);
输出将是A3210417-4BAC-1C78-BD93-4BDD286247D9:)
答案 1 :(得分:0)
试试这样:
NSString * urlName = @“assets-library://asset/asset.mov?id = A3210417-4BAC-1C78-BD93-
4BDD286247D9&安培; EXT = MOV“;
NSArray *arr = [urlName componentsSeparatedByString:@"id"];
NSString *str = [arr lastObject];
NSArray *arr1 = [str componentsSeparatedByString:@"&"];
NSLog(@"array is %@",arr1);
NSString *str2 = [[arr1 objectAtIndex:0] substringFromIndex:1];
NSLog(@"str2 is %@",str2);