Permalink
Browse files

Merge pull request #71 from mfrawley/master

Fixed nil image crash on shared photo streams
  • Loading branch information...
2 parents b108d07 + f933191 commit a75bb562e10402c6e8849dd39337dcff7ed5b65a jvanmetre committed Jan 20, 2014
Showing with 20 additions and 17 deletions.
  1. +20 −17 Classes/ELCImagePicker/ELCImagePickerController.m
@@ -78,26 +78,29 @@ - (void)selectedAssets:(NSArray *)assets
[workingDictionary setObject:obj forKey:UIImagePickerControllerMediaType];
- //defaultRepresentation returns image as it appears in photo picker, rotated and sized,
- //so use UIImageOrientationUp when creating our image below.
+ //This method returns nil for assets from a shared photo stream that are not yet available locally. If the asset becomes available in the future, an ALAssetsLibraryChangedNotification notification is posted.
ALAssetRepresentation *assetRep = [asset defaultRepresentation];
- CGImageRef imgRef = nil;
- UIImageOrientation orientation = UIImageOrientationUp;
-
- if (_returnsOriginalImage) {
- imgRef = [assetRep fullResolutionImage];
- orientation = [assetRep orientation];
- } else {
- imgRef = [assetRep fullScreenImage];
+ if(assetRep != nil) {
+ CGImageRef imgRef = nil;
+ //defaultRepresentation returns image as it appears in photo picker, rotated and sized,
+ //so use UIImageOrientationUp when creating our image below.
+ UIImageOrientation orientation = UIImageOrientationUp;
+
+ if (_returnsOriginalImage) {
+ imgRef = [assetRep fullResolutionImage];
+ orientation = [assetRep orientation];
+ } else {
+ imgRef = [assetRep fullScreenImage];
+ }
+ UIImage *img = [UIImage imageWithCGImage:imgRef
+ scale:1.0f
+ orientation:orientation];
+ [workingDictionary setObject:img forKey:UIImagePickerControllerOriginalImage];
+ [workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:UIImagePickerControllerReferenceURL];
+
+ [returnArray addObject:workingDictionary];
}
- UIImage *img = [UIImage imageWithCGImage:imgRef
- scale:1.0f
- orientation:orientation];
- [workingDictionary setObject:img forKey:UIImagePickerControllerOriginalImage];
- [workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:UIImagePickerControllerReferenceURL];
-
- [returnArray addObject:workingDictionary];
}
if (_imagePickerDelegate != nil && [_imagePickerDelegate respondsToSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:)]) {

0 comments on commit a75bb56

Please sign in to comment.