Guest User

Untitled

a guest
Aug 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. App crashes iPhone Sim when selecting from Photo Library
  2. 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)'
  3. *** Call stack at first throw:
  4. (
  5. 0 CoreFoundation 0x02392c99 __exceptionPreprocess + 185
  6. 1 libobjc.A.dylib 0x024e05de objc_exception_throw + 47
  7. 2 CoreFoundation 0x0234b3f8 +[NSException raise:format:arguments:] + 136
  8. 3 CoreFoundation 0x0234b36a +[NSException raise:format:] + 58
  9. 4 CoreFoundation 0x02391505 -[__NSCFDictionary setObject:forKey:] + 293
  10. 5 PhotoLibrary 0x0b47414e __PLNotifyImagePickerOfImageAvailability_block_invoke_1 + 161
  11. 6 PhotoLibrary 0x0b515ac1 __-[PLAssetsSaver requestImageFromAsset:withFormat:completionBlock:synchronous:]_block_invoke_1 + 45
  12. 7 MediaPlayer 0x0b9e7141 PUTReceivedImageFromAssetURL + 169
  13. 8 MediaPlayer 0x0b9e88c7 do_ReturnImageDataForAssetURL + 225
  14. 9 MediaPlayer 0x0b9e8c4e _XReturnImageDataForAssetURL + 435
  15. 10 MediaPlayer 0x0b9e8a64 PersistentURLTranslatorClient_server + 125
  16. 11 libSystem.B.dylib 0x972d06fb dispatch_mig_server + 232
  17. 12 MediaPlayer 0x0b9e871d __getClientMIGMux_block_invoke_1 + 45
  18. 13 libSystem.B.dylib 0x972aa498 _dispatch_source_latch_and_call + 62
  19. 14 libSystem.B.dylib 0x9729d3d2 _dispatch_source_invoke + 210
  20. 15 libSystem.B.dylib 0x9729bf59 _dispatch_queue_invoke + 163
  21. 16 libSystem.B.dylib 0x9729c495 _dispatch_queue_drain + 258
  22. 17 libSystem.B.dylib 0x9729bee8 _dispatch_queue_invoke + 50
  23. 18 libSystem.B.dylib 0x9729bcfe _dispatch_worker_thread2 + 240
  24. 19 libSystem.B.dylib 0x9729b781 _pthread_wqthread + 390
  25. 20 libSystem.B.dylib 0x9729b5c6 start_wqthread + 30
  26. )terminate called after throwing an instance of 'NSException'
  27.  
  28. - (IBAction)getImage
  29. {
  30. // Create image picker controller
  31.  
  32. self.imgPicker = [[UIImagePickerController alloc] init];
  33. self.imgPicker.delegate = self;
  34. self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  35. [self presentModalViewController:self.imgPicker animated:YES];
  36.  
  37. }
  38.  
  39. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  40. {
  41. self.photo = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
  42. [[picker parentViewController] dismissModalViewControllerAnimated:YES];
  43. }
  44.  
  45. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
  46. NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
  47. NSString *hour = [components hour] < 10 ? [NSString stringWithFormat:@"0%i", [components hour]] : [NSString stringWithFormat:@"%i", [components hour]];
  48. NSString *minute = [components minute] < 10 ? [NSString stringWithFormat:@"0%i", [components minute]] : [NSString stringWithFormat:@"%i", [components minute]];
  49. NSString *second = [components second] < 10 ? [NSString stringWithFormat:@"0%i", [components second]] : [NSString stringWithFormat:@"%i", [components second]];
  50. NSString *day = [components day] < 10 ? [NSString stringWithFormat:@"0%i", [components day]] : [NSString stringWithFormat:@"%i", [components day]];
  51. NSString *month = [components month] < 10 ? [NSString stringWithFormat:@"0%i", [components month]] : [NSString stringWithFormat:@"%i", [components month]];
  52. NSString *year = [NSString stringWithFormat:@"%i", [components year]];
  53. NSString *fileName = [NSString stringWithFormat:@"%@_%@_%@_%@_%@_%@.png", day, month, year, hour, minute, second];
  54. NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%@", fileName]];
  55. [UIImagePNGRepresentation(img) writeToFile:pngPath atomically:YES];
  56.  
  57. if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera)
  58. UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
  59.  
  60. [[picker parentViewController] dismissModalViewControllerAnimated:YES];
  61. }
Add Comment
Please, Sign In to add comment