Last active
December 25, 2015 03:19
-
-
Save lucianboboc/6909190 to your computer and use it in GitHub Desktop.
NSData From Asset Representation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSData *) getDataFromAssetRepresentation: (ALAssetRepresentation *) representation | |
{ | |
if(!representation) | |
{ | |
NSLog(@"asset representation is NIL!"); | |
return nil; | |
} | |
uint8_t *buffer = malloc(representation.size); | |
NSError *error = nil; | |
NSUInteger bufferLength = [representation getBytes:buffer fromOffset: 0 length:representation.size error: &error]; | |
if(error) | |
{ | |
NSLog(@"asset representation getBytes error: %@",error.localizedDescription); | |
if(buffer) | |
free(buffer); | |
return nil; | |
} | |
else | |
{ | |
NSData *assetData = [NSData dataWithBytes: buffer length: bufferLength]; | |
if(buffer) | |
free(buffer); | |
return assetData; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment