Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- App crashes iPhone Sim when selecting from Photo Library
- 2011-10-31 12:29:27.195 LognLoad[49923:7703] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: UIImagePickerControllerOriginalImage)'
- *** Call stack at first throw:
- (
- 0 CoreFoundation 0x02392c99 __exceptionPreprocess + 185
- 1 libobjc.A.dylib 0x024e05de objc_exception_throw + 47
- 2 CoreFoundation 0x0234b3f8 +[NSException raise:format:arguments:] + 136
- 3 CoreFoundation 0x0234b36a +[NSException raise:format:] + 58
- 4 CoreFoundation 0x02391505 -[__NSCFDictionary setObject:forKey:] + 293
- 5 PhotoLibrary 0x0b47414e __PLNotifyImagePickerOfImageAvailability_block_invoke_1 + 161
- 6 PhotoLibrary 0x0b515ac1 __-[PLAssetsSaver requestImageFromAsset:withFormat:completionBlock:synchronous:]_block_invoke_1 + 45
- 7 MediaPlayer 0x0b9e7141 PUTReceivedImageFromAssetURL + 169
- 8 MediaPlayer 0x0b9e88c7 do_ReturnImageDataForAssetURL + 225
- 9 MediaPlayer 0x0b9e8c4e _XReturnImageDataForAssetURL + 435
- 10 MediaPlayer 0x0b9e8a64 PersistentURLTranslatorClient_server + 125
- 11 libSystem.B.dylib 0x972d06fb dispatch_mig_server + 232
- 12 MediaPlayer 0x0b9e871d __getClientMIGMux_block_invoke_1 + 45
- 13 libSystem.B.dylib 0x972aa498 _dispatch_source_latch_and_call + 62
- 14 libSystem.B.dylib 0x9729d3d2 _dispatch_source_invoke + 210
- 15 libSystem.B.dylib 0x9729bf59 _dispatch_queue_invoke + 163
- 16 libSystem.B.dylib 0x9729c495 _dispatch_queue_drain + 258
- 17 libSystem.B.dylib 0x9729bee8 _dispatch_queue_invoke + 50
- 18 libSystem.B.dylib 0x9729bcfe _dispatch_worker_thread2 + 240
- 19 libSystem.B.dylib 0x9729b781 _pthread_wqthread + 390
- 20 libSystem.B.dylib 0x9729b5c6 start_wqthread + 30
- )terminate called after throwing an instance of 'NSException'
- - (IBAction)getImage
- {
- // Create image picker controller
- self.imgPicker = [[UIImagePickerController alloc] init];
- self.imgPicker.delegate = self;
- self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- [self presentModalViewController:self.imgPicker animated:YES];
- }
- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
- {
- self.photo = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
- [[picker parentViewController] dismissModalViewControllerAnimated:YES];
- }
- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
- NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
- NSString *hour = [components hour] < 10 ? [NSString stringWithFormat:@"0%i", [components hour]] : [NSString stringWithFormat:@"%i", [components hour]];
- NSString *minute = [components minute] < 10 ? [NSString stringWithFormat:@"0%i", [components minute]] : [NSString stringWithFormat:@"%i", [components minute]];
- NSString *second = [components second] < 10 ? [NSString stringWithFormat:@"0%i", [components second]] : [NSString stringWithFormat:@"%i", [components second]];
- NSString *day = [components day] < 10 ? [NSString stringWithFormat:@"0%i", [components day]] : [NSString stringWithFormat:@"%i", [components day]];
- NSString *month = [components month] < 10 ? [NSString stringWithFormat:@"0%i", [components month]] : [NSString stringWithFormat:@"%i", [components month]];
- NSString *year = [NSString stringWithFormat:@"%i", [components year]];
- NSString *fileName = [NSString stringWithFormat:@"%@_%@_%@_%@_%@_%@.png", day, month, year, hour, minute, second];
- NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%@", fileName]];
- [UIImagePNGRepresentation(img) writeToFile:pngPath atomically:YES];
- if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera)
- UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
- [[picker parentViewController] dismissModalViewControllerAnimated:YES];
- }
Add Comment
Please, Sign In to add comment