我需要将文件从 我使用此代码 怎么能正确地做到这一点?ALAssetsLibrary
转换为NSData
,但我收到的是 path = file:///assets-library://asset/asset.mp4?....
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
NSData *dates = [NSData dataWithContentsOfURL: url];
答案 0 :(得分:3)
希望这会对你有所帮助
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:[[self.imagedata objectAtIndex:i] valueForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset)
{
ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];//this is NSData may be what you want
[data writeToFile:photoFile atomically:YES];//you can save image later
}
failureBlock:^(NSError *err) {
NSLog(@"Error: %@",[err localizedDescription]);
}];