Last active
September 21, 2016 08:23
-
-
Save ShadoFlameX/5132970 to your computer and use it in GitHub Desktop.
Obtain raw image data from an iOS user's photo library
This file contains 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
- (void)imagePickerController:(UIImagePickerController *)picker | |
didFinishPickingMediaWithInfo:(NSDictionary *)info | |
{ | |
NSURL *assetURL = info[UIImagePickerControllerReferenceURL]; | |
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init]; | |
[assetLibrary assetForURL:assetURL resultBlock:^(ALAsset *asset) { | |
ALAssetRepresentation *representation = [asset defaultRepresentation]; | |
Byte *buffer = (Byte *)malloc(representation.size); | |
NSError *error = nil; | |
NSUInteger size = [representation getBytes:buffer | |
fromOffset:0 | |
length:representation.size | |
error:&error]; | |
if (size == 0) { | |
NSLog(@"Could not get asset data"); | |
return; | |
} | |
NSData *imageData = [NSData dataWithBytesNoCopy:buffer length:size]; | |
// todo: upload data to server | |
} failureBlock:^(NSError *error) { | |
NSLog(@"Could not get asset"); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment