when i ask to show imagePicker with Photos from PhotoAlbum i get crash:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/9D75B5EC-6CC9-4306-B4A1-88C369FEEC6C/AlterGeo.app> (loaded)' with name 'PLUIPrivacyViewController''
- (void)showImagePicker {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if ([imagePicker respondsToSelector:#selector(setAllowsEditing:)]) {
[imagePicker setAllowsEditing:_editable];
}
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePicker setDelegate:self];
[[self getNavigationController] presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
- (UINavigationController *)getNavigationController {
if (_delegate && [_delegate isKindOfClass:[UIViewController class]]) {
return [(UIViewController *)_delegate navigationController];
}
return nil;
}
If it first launch and i ios ask for permissions (UIAlertView allow/deny) it will be crash, but if i have already granted permissons (allow) it will be work fine.
How i can resolve it?
I find solution of my problem.
The code is not mine, it was outsource people with strange relisation of project.. anyway they ask for every ViewController xib file in category for UiViewController
- (NSString *)nibName {
if ( ! [NSStringFromClass([self class]) isEqualToAnyString:[NSArray arrayWithObjects:
#"UIStatusBarViewController",
#"UIZoomViewController",
#"PLUIPrivacyViewController",
nil]]) {
return NSStringFromClass([self class]);
}
return nil;
}
and in ios6.0 apple added PLUIPrivacyViewController whitch dont have own nib.. I just add PLUIPrivacyViewController in exceptions..
Ofcource better way to make white list of controllers6 cuz the project is realy old and will not modify, but apple can add some other controllesrs without nibs...
But its lot of time.
Related
My application is is landscape mode. I am presenting the activity view controller in landscape only with the following lines of code:-
NSArray *shrArr = [NSArray arrayWithObjects:[NSString stringWithFormat:#"%#", KHL_SHARE_TEXT], nil];
UIActivityViewController *shareUIAVC = [[UIActivityViewController alloc] initWithActivityItems: shrArr applicationActivities: nil];
if([shareUIAVC respondsToSelector:#selector(setValue:forKey:)])
{
[shareUIAVC setValue:KHL_SHARE_MAIL_TEXT forKey:#"subject"];
}
if([shareUIAVC respondsToSelector:#selector(popoverPresentationController)])
{
shareUIAVC.popoverPresentationController.sourceView = self.menuButton;
shareUIAVC.popoverPresentationController.sourceRect = self.menuButton.bounds;
}
[self presentViewController:shareUIAVC animated: YES completion: nil];
The Activity view controller opens in landscape and on choosing either message or mail and either sending or cancelling the message or mail composer, the app crashes with the following logs.
* Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation '(7)' must match a supported interface orientation: 'landscapeLeft, landscapeRight'!'
* First throw call stack:
(0x186f991b8 0x1859d055c 0x186f99100 0x18cf44670 0x18d810428 0x18d19abf0 0x18d1be6c8 0x18cf7b1bc 0x18cf21f14 0x18d1bd920 0x18cf21a48 0x18d7f672c 0x18d7f6a64 0x18d067bdc 0x18d7d5ad4 0x1974b498c 0x1974cbad8 0x186f9f150 0x186e91eac 0x188b6f92c 0x188b6f798 0x188b48058 0x18d0d1684 0x18d126664 0x18a293e10 0x18a26b4c4 0x18a292a68 0x18a293488 0x186f460c0 0x186f43cf0 0x186f44180 0x186e722b8 0x188926198 0x18ceb97fc 0x18ceb4534 0x100143930 0x185e555b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
2017-06-01 16:36:17.423693
As suggesting from various sources here , I added the following code too, but that does'nt work either
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
Thanks in advance!
Add this in appdelegate
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
//self.isMailController enable while activityViewcontroller appears and disable while it dissmissed.
if(self.isMailController){
// you can check multiple viewcontroller
return UIInterfaceOrientationMaskPortrait; // if your mail viewcontroller it will display on portrait
}
return UIInterfaceOrientationMaskLandscape;
}
I am presently using UIImagePicker and my app crashes on iOS 8 with the following workflow:
Start the camera, zoom it which shows the zoom slider below and then take a picture. Select Use Photo and app crashes.
After looking more into the crash "didHideZoomSlider" message is sent to the deallocated instance of image picker view.
Here is my code:
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil];
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
[myController presentViewController:imagePicker animated:animated completion:nil];
I tried a couple of things. My controller holds a strong reference to the image picker, I tried making it a weak reference and the app still crashes. Also I need a strong reference so I actually cannot make it weak.
Although this looks like an Apple bug and someone has already logged it (http://openradar.appspot.com/18762927) I wanted to try the workaround they are using. However I am not able to get to "CAMZoomSlider" through UIImagePicker's instance.
Does anyone know how to get to CAMZoomSlider?
I was able to clear the CAZoomSlider delegate by doing the following in a subclassed UIImagePickerController class. And sure enough, it seems to have resolved the crash.
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self clearZoomSliderDelegate:self.view.subviews];
}
- (void)clearZoomSliderDelegate:(NSArray*)subviews
{
for (UIView *subview in subviews)
{
if ([subview isKindOfClass:NSClassFromString(#"CAMZoomSlider")])
{
if ([subview respondsToSelector:#selector(setDelegate:)]) {
[subview performSelector:#selector(setDelegate:) withObject:nil];
}
return;
}
else if (subview.subviews != nil) {
[self clearZoomSliderDelegate:subview.subviews];
}
}
}
Code is below and crash at [self presentModalViewController:imagePicker animated:YES]; when I use device under iOS6.1. It work fine in iOS 7.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init] ;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:imagePicker animated:YES];
}
Get the error in console: ImageIO: PNG invalid PNG file: iDOT doesn't point to valid IDAT chunk
Any suggestion is appreciated.
Ok, I have fixed the bug, I want to share it out with detail process.
When it crashes, it shows ImageIO: PNG invalid PNG file: iDOT doesn't point to valid IDAT chunk
libc++abi.dylib: handler threw exception in the console, I have no idea about "ImageIO balabala..." but I think I may catch the exception when I noticed "libc++abi.dylib: handler threw exception". So I add #try #catch in my code, code is below.
#try {
[self presentModalViewController:imagePicker animated:YES] ;
}
#catch (NSException *exception) {
NSLog(#"exception:%#", exception) ;
}
#finally {
}
Then I run it again, I got exception:preferredInterfaceOrientationForPresentation must return a supported interface orientation!.
The problem seems to be a little obvious, after google it, I find a solution which is to override some orientation related methods to provide a preferred interface orientation in UIImagePickerController.
So I subclass the UIImagePickerController and implement some methods like this below:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
Then run again, no crash , cheers !!!
Replace this line:
[self presentModalViewController:imagePicker animated:YES];
With
[self presentViewController:picker animated:YES completion:nil];
I have a framework that creates some views, the app that uses the framework calls a method from it and pass in the current view controller, the framework then calls presentModalViewController to display a view.
It was working just fine with iOS 6.1 SDK but when I updated to Xcode 5 and iOS 7 SDK I don't see the modal view anymore, instead all I get is a blank screen.
EDIT
Heres some code:
The Framework is called "testityi"
testityi.m
#import "TestViewController.h"
#implementation testitiy
- (NSString*) sayHi : (NSString*) name {
return [NSString stringWithFormat:#"Hello %#", name];
}
- (void) displayView:(UIViewController *)parentController {
TestViewController* controller = [[TestViewController alloc] init];
[parentController presentViewController:controller animated:YES completion:nil];
}
TestViewController is simply a view with a label that says "View from framework"
The framework itself works fine, calling sayHi method works just fine.
The third party app has a view with a label and a button which calls sayHi method and then displayView method, heres the view controller code:
MainViewController.m
- (IBAction)buttonPressed:(id)sender {
testitiy* framework = [[testitiy alloc] init];
NSString* msg = [NSString stringWithFormat:#"Calling sayHi method on framework...\n result: %#", [framework sayHi:#"John"]];
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"sayHi method call" message:msg delegate:self cancelButtonTitle:#"Ok, show me the view" otherButtonTitles:nil, nil];
[alert show];
}
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == [alertView cancelButtonIndex]) {
testitiy* framework = [[testitiy alloc] init];
[framework displayView:self];
}
}
The alert button action is also working correctly, I added a NSLog before and its working.
After clicking the alert button a view is presented but instead of containing the label "View from framework" I get a blank screen.
You can see the code on Github
EDIT 2
I got it... I wasn't calling initWithBundle on the ViewController from the framework, I added the a custom init method that calls:
framework: TestViewController.m
+ (NSBundle *)frameworkBundle {
static NSBundle* frameworkBundle = nil;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
NSString* mainBundlePath = [[NSBundle mainBundle] resourcePath];
NSString* frameworkBundlePath = [mainBundlePath stringByAppendingPathComponent:#"testity.bundle"];
frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
});
return frameworkBundle;
}
- (id) initWithFramework {
NSBundle* bundle = [[self class] frameworkBundle];
self = [super initWithNibName:#"TestViewController" bundle: bundle];
return self;
}
And changed testitiy.m
- (void) displayView:(UIViewController *)parentController {
TestViewController* controller = [[TestViewController alloc] initWithFramework];
[parentController presentViewController:controller animated:YES completion:nil];
//[parentController.navigationController pushViewController:controller animated:YES];
}
And now its working...
I hope this helps someone else but I'm guessing it was a stupid mistake of mine.
Sorry for all the trouble and thanks for your time!
So after a while I finally understand the issue:
When using a custom framework, all resources like images and NIB files have to be manually included in the third-party app so that it has access to those files.
My problem was that I was including the resources (stored in a bundle) into the third-party app but the framework was trying to display the View based on its own resources, which the app couldn't access, for that reason I was getting a blank screen.
I just needed to tell the framework to use the included bundle into the third-party app to display that View (using the initWithNibName: Bundle method).
See EDIT 2 in the question to see the code that solved my problem.
Hope this helps someone. :-)
I researched a lot on this one. On touching an button, I have to pick an image from device and display on the screen.
But it causes my app to crash when button is touched/pressed.
It crashes from this line of code:
[self presentModalViewController:myPhotopicker animated:YES];
I am developing an iPad app using Xcode 4.2. I am using iPad 5.0 simulator for testing. And my system runs on Mac OS X, version 10.6.8.
Following function is called when button is pressed:
-(IBAction)getPhoto:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
if (myPhotopicker==nil) { myPhotopicker = [[UIImagePickerController alloc] init];
myPhotopicker.delegate = self; }// create once!
myPhotopicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:myPhotopicker animated:YES];
} else {
NSString *str = #"Photo Album is not available!";
}
}
I tried your code and can reproduce the crash in the simulator.
But it is working fine on my iPhone 4 with iOS 4.2.
That said, I made my gallery in the simulator contain some photos.
(Start in-simulator Safari, open some page, save some pictures by long pressing on them and choosing save from the menu.)
Now, the simulator writes
2012-05-08 15:53:55.605 test[5870:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'On iPad, UIImagePickerController must be presented via UIPopoverController'
to the console.
Okay, read, done:
-(IBAction)getPhoto:(UIButton *)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
if (myPhotopicker==nil) {
myPhotopicker = [[UIImagePickerController alloc] init];
myPhotopicker.delegate = self;
}// create once!
myPhotopicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// iPad Code:
UIPopoverController *popover =
[[UIPopoverController alloc] initWithContentViewController:myPhotopicker];
[popover presentPopoverFromRect:sender.bounds
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
} else {
// iPhone Code:
[self presentModalViewController:myPhotopicker animated:YES];
}
} else {
NSLog(#"Photo Album is not available!");
}
}
And now it looks like that: