iOS Version Checking gives warning - iphone

In my app I need to present a view controller. The 6.0 method for presenting a view controller is presentViewController:animated:completion:. I want to support 4.3 also. In 4.3 the method to be called is presentModalViewController:animated:. So I use respondsToSelector: to find out whether the method is supported. But when I compile the app for 6.0 it gives warning message as
presentModalViewController:animated: is deprecated: first deprecated in iOS 6.0
Can anyone know how to get rid of this warning. I also do not have 4.3 device to test whether it works. I need to assume that the code I write should work on 4.3.
if([myViewController respondsToSelector:#selector(presentModalViewController:animated:)]){
[myViewController presentModalViewController:anotherViewController animated:YES];
}else{
[myViewController presentViewController:anotherViewController animated:YES completion:nil];
}

you could make check opposite for respondsToSelector it might help, and this is the way to go actually if you are supporting older versions:)
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)]){
[self presentViewController:anotherViewController animated:YES completion:nil];
} else {
[self presentModalViewController:anotherViewController animated:YES];
}

You can enable / disable warning with pragma into your code, but they are not very friendly to use. And i don't remember the specific pragma for this kind of warning. But some guys here will told you.
By the way you can use a simple
[id performSelector:<#(SEL)#> withObject:<#(id)#>]
will do the trick

I had mistakenly set the deployment target to 6.0. So it was showing the mentioned warning message. No warning message after I changed the deployment target to 4.3(which I need to support). Thanks for the answers!.

Related

cut/copy/paste functionality stopped working in my iOS application

UPDATE: cut/copy/paste disabled in my app.
I am confused with my iOS app while developing for iPhone devices. Execution flow enters a point like the code below
[self navigationController] pushViewController:chooseDeviceView animated:YES];
[chooseDeviceView release];
[numberTextField setText:#""];
The view changes and things "work properly". The problem is that after this the cut/copy/paste functionality is missing in my app.
Don't really know how to start debugging the issue. Does it ring a bell to anybody?
That was a very complicated issue for a beginner. Finally the issue was a little bit related with status message corrupts main window in my iPhone app
Add in your new viewController this:
- (BOOL)canBecomeFirstResponder {
return YES;
}
It should solve your issue.

How to send an email in iOS6

I have been following a tutorial series and I am trying to learn how to send an email.
I typed in the following line of code but it says it was deprecated in iOS 6.
[self presentModalViewController:picker animated:YES];
What would be the replacement for this code in iOS 6 be and would it work on iOS 5 devices?
That method was deprecated and is replaced by
presentViewController:animated:completion:
But really, that's right at the top within the documentation of presentModalViewController:animated:.

ViewDidAppear crashes on iOS 5.0 simulator

The following code works fine from iOS 3.0 to iOS 4.3 simulator but crashes on iOS5
-(void)viewWillAppear:(BOOL)animated {
[self.tableView reloadData];
[super viewWillAppear:animated];
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationController viewDidAppear:animate];
}
I got exc_bad_access in [self.navigationController viewDidAppear:animate] and it makes the app crashes.
It works fine without any problem in the previous verison.
This app is developed in XCode4 with deployment target 3.0. My user just found the app crashes when he upgraded his iPhone with iOS5.
I am being able to reproduce theproblem but not sure how to fix it.
Can anybody shed some light?
[self.navigationController viewDidAppear:animate]; is the problem here. In iOS 5 it's going to recursively call this view controller's viewDidAppear method over and over until it just crashes. Why exactly do you need to call viewDidAppear manually on your navigation controller? If it's actually necessary to get your code working, you might want to backtrack a bit as something else must be wrong if you're needing to do this.
One other thing that's just good housekeeping: in your viewWillAppear, [super viewWillAppear:animated]; should come first it that method.

iOS 5 SDK treating UIViews differently

My app which use to work perfectly being compiled in xCode 4.0.2 no longer works correcly compiled in xCode 4.2 with the new SDK.
My modal views are working very different, some states not being detected, or other dismissals not working. For example this use to work to dismiss 2 stacked modal views:
if(self.parentViewController.parentViewController)
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
else
[self dismissModalViewControllerAnimated:YES];
Now this just dismisses the first view...
I've been looking for documentation on these changes but have found none. Primary app delegate seems to be working differently too.
Help greatly appreciated.
There is a new property in iOS 5 named presentingViewController. The meaning of parentViewController got changed a bit with the new container view controller API, so it may not always be set when you think it is. That's what presentingViewController is now for.
if ([self respondsToSelector:#selector(presentingViewController)])
[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES]; // for IOS 5+
} else {
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES]; // for pre IOS 5
}

-setStatusBarHidden:animated: is deprecated

At the start of my app, the status bar is hidden, due to the Info.plist setting called Status bar is initially hidden. Later on, I want to show the status bar using:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
but I get a warning saying that the function is deprecated. Does anybody know what the new function is?
setStatusBarHidden:withAnimation: is the new method, which takes a UIStatusBarAnimation instead of a BOOL, so you can choose what animation is used to hide the status bar.
It is:
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation
See the UIApplication class reference for more info.
If you are trying to write code for both iOS 3.x and iOS 4.x, you are going to run into a further issue that the new method is not available in the old iOS. See this question for further info.
Add this to your AppDelegate.m
[UIApplication sharedApplication].statusBarHidden = YES;