Transform from ios6 to ios7 - ipad

I have an universal app where I successfully upgraded the iPhone component to ios7.
The ipad component however is not running anymore. I get the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISplitViewController tabBar]: unrecognized selector sent to instance 0x8d9eef0'
I have no idea what happened. I did not touch the ipad side of things whatsoever.
I am running: 11A4449d build and 5A11365y build for x-code on a mac machine.
After this code the error happens:
- (void) awakeFromNib {
[super awakeFromNib];
// whenever I come out of a storyboard, I make myself the delegate of any splitview I am in
self.splitViewController.delegate = self;
}

In this method: I set the selected image on a tab bar for the iPhone.
But did not realise that the iPad will not like it. So I put a selective statement (if !iPad) around it to fix it.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
BOOL piPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
if (!piPad)
{
// **************************************************************************************************
// Assign tab bar item with titles and selected images
UITabBarController *pTabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *pTabBar = pTabBarController.tabBar;
UITabBarItem *pTabBarItem0 = [pTabBar.items objectAtIndex:0];
pTabBarItem0.title = #"List";
pTabBarItem0.selectedImage = [UIImage imageNamed:#"tabBarList_30x30_selected"];
pTabBarItem0.image = [UIImage imageNamed:#"tabBarList_30x30.png"];
// **************************************************************************************************
}
return YES;

Related

UISplitViewControllerDisplayModePrimaryHidden Crashing App On iPad

My application support is iPad only.
I have UISplitViewController in it.
Left Menu
UIViewController
UITableView
UITableViewCell
UILabel (Added UITapGestureRecognizer)
UIImageView
Center View
UIViewController
UIView
I'm Showing the popover when user taps on UserName label (Left menu -> Tableview -> Cell -> Label)
So my code in cellForRowAtIndexPath method is below.
__weak LeftMenuUserTCell *weakCell = cell;
cell.didTapProfileOption = ^{
NSLog(#"Option Tapped");
[self showMyProfilePopupFrom:weakCell.lblUserName inView:weakCell.lblUserName.superview];
};
and i'm presenting popover like this
-(void)showMyProfilePopupFrom:(UIView *)sourceView inView:(UIView *)parentView
{
ListViewController *listView=[[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"ListViewController"];
listView.listDelegate=self;
NSArray *optionList=#[#"My Profile",#"Change Password",#"Sign Out"];
listView.dataArray=[optionList mutableCopy];
listView.selectedItemIndex = -1;
listView.listType = 1;
listView.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popover = listView.popoverPresentationController;
listView.preferredContentSize = CGSizeMake(200, 150);
//popover.delegate = self;
popover.sourceView = sourceView;
popover.sourceRect = sourceView.bounds;
popover.permittedArrowDirections = UIPopoverArrowDirectionUp;
[self presentViewController:listView animated:YES completion:nil];
}
Till now everything is working fine.
Now I have to keep hidden left menu by default so i wrote following code in AppDelegate where i'm setting up UISplitViewController.
self.rootSplitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
Now Problem is my app is crashing when i tap the mentioned label. I have checked that my application is even not crashing when i comment out the above line (UISplitViewControllerDisplayModePrimaryHidden).
Following is the crash log :
MyApp[785:371642] invalid mode 'kCFRunLoopCommonModes' provided to
CFRunLoopRunSpecific - break on
_CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.
MyApp[785:371642] * Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '* -[__NSPlaceholderDictionary
initWithObjects:forKeys:count:]: attempt to insert nil object from
objects[0]'
Testing on iPad Air (iOS 10.3.3)

"NSInternalInconsistencyException [...] Sigh. Contentview size is zero." crash when using a UINavigationController

My code runs perfectly fine on iOS 10.3.3, whereas when I run the same code on iOS 11.2.1, it causes a crash at launch time with the following error:
Assertion failure in -[_UINavigationBarVisualProviderModernIOS _contentViewFittingHeight], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3698.33.7/_UINavigationBarVisualProviderModernIOS.m:569
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Sigh. Contentview size is zero.'
I cleaned the code, cleared the derived data, but those did not solve the issue.
There was an issue in the library I was using for Slide menu "iOS-Slide-Menu". So, I simply changed this two very methods in the library which then worked fine.
- (void)setup
{
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:#"ssidName"];
[[NSUserDefaults standardUserDefaults] synchronize];
if (singletonInstance)
NSLog(#"Singleton instance already exists. You can only instantiate one instance of SlideNavigationController. This could cause major issues");
singletonInstance = self;
self.menuRevealAnimationDuration = MENU_SLIDE_ANIMATION_DURATION;
self.menuRevealAnimationOption = MENU_SLIDE_ANIMATION_OPTION;
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Update shadow size of enabled
if (self.enableShadow)
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;
self.landscapeSlideOffset = self.view.frame.size.width/6;
self.portraitSlideOffset = self.view.frame.size.width/6;
self.panGestureSideOffset = 0;
self.avoidSwitchingToSameClassViewController = YES;
self.enableShadow = YES;
self.enableSwipeGesture = NO;
self.delegate = self;
// When menu open we disable user interaction
// When rotates we want to make sure that userInteraction is enabled again
[self enableTapGestureToCloseMenu:NO];
if (self.menuNeedsLayout)
{
[self updateMenuFrameAndTransformAccordingToOrientation];
// Handle different horizontal/vertical slideOffset during rotation
// On iOS below 8 we just close the menu, iOS8 handles rotation better so we support keepiong the menu open
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0") && [self isMenuOpen])
{
Menu menu = (self.horizontalLocation > 0) ? MenuLeft : MenuRight;
[self openMenu:menu withDuration:0 andCompletion:nil];
}
self.menuNeedsLayout = NO;
}
}
Fixed out, that two lines must be in viewWillLayoutSubviews instead of setup method. And like #Ishika said, this is the problem of iOS-Slide-Menu.
self.enableShadow = YES;
self.enableSwipeGesture = YES;
This error occured to me with Xcode 10.2.1 and SideMenu 6.0.4. I ended up configuring the navigation controller programmatically, which solved the issue.
let sideMenuVc = UISideMenuNavigationController(rootViewController: <view controller>)

Application Crashes on Cancelling Message Composer Or Mail Composer view

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;
}

Using UIImagePicker in iPad with Landscape only on iOS 6

I am making an iPad app that only supports landscape orientations, and in that app i am calling the photo Library using the following code
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects: (NSString *) kUTTypeImage, nil];
self.iPadPopoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[self.iPadPopoverController setDelegate:self];
[self.iPadPopoverController presentPopoverFromRect:CGRectMake(490, 638, 44, 44) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
However, This causes a crash with the following exception:
Uncaught exception: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES
The Reason for the Crash:
After researching I found that the crash was due to the UIImagePickerController always being displayed in Portrait mode even when the interface orientation is Landscape.
How I tried to solve it:
After reading the
iOS6 release notes and several questions previously posted; I found that the method from which the crash was originating was in the Application Delegate's
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
the obvious solution was to have it return UIInterfaceOrientationMaskLandscape|UIInterfaceOrientationMaskPortrait
however, I want my app to support Landscape only! so my first solution was to add a Boolean flag to the App Delegate and set it to YES just before I call the UIImagePickerController and set back to NO after I dismiss it.
And it worked, but I was not happy with it, it felt like a messy solution. So instead I had the method check for its caller and if it were the function that initializes the UIImagePickerController then the method would return UIInterfaceOrientationMaskPortrait.
-(BOOL) iPadPopoverCallerFoundInStackSymbols{
NSArray *stackSymbols = [NSThread callStackSymbols];
for (NSString *sourceString in stackSymbols) {
if ([sourceString rangeOfString:#"[UIViewController(PhotoImport) importPhotoFromAlbum]"].location == NSNotFound) {
continue;
}else{
return YES;
}
}
return NO;
}
That solution worked on the simulator and on the device.
Here is the weird part
After submitting my app to the store, all my users were reporting that the app was crashing whenever they would access the photo library. I looked over the crash reports and found that the crash was occurring due to the exception mentioned above. I could not understand why this was happening.
So I submitted a TSI(Technical Support Incident) to apple about this issue. They replied that the stack symbols are not human readable after the app is archived and that is why my check would always fail.
They also suggested testing on devices by archiving the project first into a .ipa file and installing it through iTunes inorder to detect issues like this in the future.
That's Great but my problem still exists
Does anyone know how to solve this problem?
In info.plist declare all orientations as supported.
You no longer need method application:supportedInterfaceOrientationsForWindow:, so it can be deleted.
Subclass root view controller
Add following methods:
- (BOOL)shouldAutorotate {
return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
return self.interfaceOrientation;
} else {
return UIInterfaceOrientationLandscapeRight;
}
}
If you present modal view controllers and don't want them to be rotated, then you need to add this code to their root controllers too.

UIPageViewController throws SIGABRT on orientation change

I have the following code to display a magazine type app. When the app is rotated it runs this code. I made sure that it is only run when rotated to supported orientations. When this function returns, the app fails with a SIGABRT. There is no other indication as to why.
I know it's this function because when I remove it the program does not fail.
- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController
spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
//If portrait mode, change to single page view
if(UIInterfaceOrientationIsPortrait(orientation)){
UIViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:currentViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];
self.pageViewController.doubleSided = NO;
return UIPageViewControllerSpineLocationMin;
//If landscape mode, change to double page view
}else{
//Get current view
UIViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
//Create an array to store, views
NSArray *viewControllers = nil;
NSUInteger currentIndex = self.currentPage;
//Conditional to check if needs page before or after
if(currentIndex == 1 || currentIndex %2 == 1){
UIViewController *nextViewController = [self pageViewController:self.pageViewController viewControllerAfterViewController:currentViewController];
viewControllers = [NSArray arrayWithObjects:currentViewController,nextViewController, nil];
}else{
UIViewController *previousViewController = [self pageViewController:self.pageViewController viewControllerBeforeViewController:currentViewController];
viewControllers = [NSArray arrayWithObjects:previousViewController, currentViewController, nil];
}
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];
return UIPageViewControllerSpineLocationMid;
}
//return UIPageViewControllerSpineLocationMid;
}
Alas, borrrden is probably right. One of your IBOutlets is probably missing from your XIB. Make sure ALL of your IBs are connected properly, and if the problem continues, say so.
Well you didn't provide the output from the console, which would be nice. Giving the code a quick look I would guess that one of your controllers (next or previous) is nil, and since you can't insert nil into an NSArray (except as the last object) it is throwing an error.
EDIT Well, my guess was wrong. The error message is saying that the UIViewControllers you are giving to it do not support the orientation that the page controller needs. This is because you have a method called shouldRotateToInterfaceOrientation: in your child UIViewControllers, and they are returning no for (in this case) left landscape.
I was getting the same error
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'All provided view controllers ((
"<ContentViewController: 0x6a7eac0>",
"<ContentViewController: 0x6d89f10>"
)) must support the pending interface orientation (UIInterfaceOrientationLandscapeLeft)'
Adding the following to my PageModel class, where the page layout is designed worked for me:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

Resources