How to execute a block of code in IOS7 not in IOS6? - ios

Hi In past I had developed one application which supports IOS6.Now the time came to support the same app for IOS7 also. For supporting the app for IOS6 & IOS7 I increased the Y value of each and every component by 20 pixels.
Here I am getting the OS version by using[[[UIDevice CurrentDevice]SystemVersion] floatvalue]; method.Based on that OS version I am changing the rect values for each and every component.
For handling the StatusbarStyle I am using the following methods in IOS7
1. [self setNeedsStatusBarAppearanceUpdate];
2.-(UIStatusBarStyle)preferredStatusBarStyle;
These methods are working fine in IOS7, But if I install the app in IOS6 the app is crashing due to the above two methods.
So now my requirement is I have to hide or not execute IOS7 related methods or changes in IOS6 Device.With the help of this Implementation I hope I can resolve the issue.
Even I used few methods to resolve this crash issue.The methods which I used are
1. #if __IPHONE_OS_VERSION_MAX_ALLOWED== 70000
2.#if __IPHONE_OS_VERSION_MIN_REQUIRED==70000
Here while creating the ipa file deployment Target Which I had set is 6.0. Because I have to support IOS6 & IOS7.
So please help me to resolve this issue. Thanks in Advance.

use NSFoundationVersionNumber condition for doing this Supporting iOS 6
If you need to load different resources for different app versions—and you currently identify a storyboard or XIB file in your Info.plist file—
you can use the version of the Foundation framework to determine the current system version and load the appropriate resource in application:didFinishLaunchingWithOptions:. The code below shows how to check the Foundation framework version:
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
Take a look the best answer of the same thing that you want
iOS 7 status bar back to iOS 6 default style in iPhone app?

Try checking for this condition :
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
} else {
// iOS 6
}

Related

Disable some classes when building on ios6 [duplicate]

Hi In past I had developed one application which supports IOS6.Now the time came to support the same app for IOS7 also. For supporting the app for IOS6 & IOS7 I increased the Y value of each and every component by 20 pixels.
Here I am getting the OS version by using[[[UIDevice CurrentDevice]SystemVersion] floatvalue]; method.Based on that OS version I am changing the rect values for each and every component.
For handling the StatusbarStyle I am using the following methods in IOS7
1. [self setNeedsStatusBarAppearanceUpdate];
2.-(UIStatusBarStyle)preferredStatusBarStyle;
These methods are working fine in IOS7, But if I install the app in IOS6 the app is crashing due to the above two methods.
So now my requirement is I have to hide or not execute IOS7 related methods or changes in IOS6 Device.With the help of this Implementation I hope I can resolve the issue.
Even I used few methods to resolve this crash issue.The methods which I used are
1. #if __IPHONE_OS_VERSION_MAX_ALLOWED== 70000
2.#if __IPHONE_OS_VERSION_MIN_REQUIRED==70000
Here while creating the ipa file deployment Target Which I had set is 6.0. Because I have to support IOS6 & IOS7.
So please help me to resolve this issue. Thanks in Advance.
use NSFoundationVersionNumber condition for doing this Supporting iOS 6
If you need to load different resources for different app versions—and you currently identify a storyboard or XIB file in your Info.plist file—
you can use the version of the Foundation framework to determine the current system version and load the appropriate resource in application:didFinishLaunchingWithOptions:. The code below shows how to check the Foundation framework version:
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
Take a look the best answer of the same thing that you want
iOS 7 status bar back to iOS 6 default style in iPhone app?
Try checking for this condition :
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
} else {
// iOS 6
}

Change GUI when selecting iOS 6 in Xcode 5

When I am using Xcode 5 and I set the deployment target as 7.0, the application runs perfectly with both 4-inch and 3.5-inch displays.
I have downloaded the iOS 6 SDK already.
When I change the base SDK to iOS 6 and set the deployment target as iOS 6.1 my GUI is affected in a way that changes every image, navigation bar, images and all other controls.
I am not using autolayout and have two .xib files for one UIViewController in each class.
So, how can I get fix this?
Thanks in advance.
When you compile with the iOS 6 SDK , you application is created with the iOS6 images, views, keyboards, etc...
You can't use iOS7 views if you are compiling for iOS6, you need to compile for iOS7, even thought your app is iOS6 compatible (setting the deployment target to iOS6)
Long story short - you can't use iOS 7 GUI in your iOS 6 app. If you want you can just create your custom GUI and use it in your app. But some elements will be different, you better read this guide:
Apple docs
Also if you build you app for different versions of iOS you better use auto layout:
Ray Wenderlich - Auto Layout Tutorial in iOS 7: Part 1
Ray Wenderlich - Auto Layout Tutorial in iOS 6: Part 1
Some issues of transition from iOS 6 to iOS 7:
Status bar and navigation bar issue in IOS7
Use this code:
if([[[UIDevice currentDevice] systemVersion] isEqualToString: #"7.0"])
{
//do stuff
}
else
{
// code here
}
When compiling for iOS 7 you are using iOS 7 specific GUI elements (that differs a lot from iOS 6). Phones that are still on iOS 6 (about 16%) will however see the iOS 6 GUI elements for obvious reasons, even if you compile it for iOS 7.
There is really no way to resolve this, you should simply develop for iOS 7 and let iOS 6 users still have iOS 6 GUI elements.
If your application is working fine in iOS 7 and you need to run it iOS 6 then you need to manage the application using this method:
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending){
//CGRect gridFrame;
if ([[UIScreen mainScreen] bounds].size.height == 568) {
// Do nothing if already managed
}else{
// Do nothing if already managed
}
}else{
//CGRect gridFrame for ios6;
if ([[UIScree`enter code here`n mainScreen] bounds].size.height == 568) {
//Manage frame here
}else{
//Manage frame here
}
}

Button Images Don't Show When Using Xcode 5

I have several buttons with images assigned to each. In Xcode 4.6 using the iOS 6 SDK, they show like they should. When using Xcode 5 with the iOS 7 SDK, the images are not there. In the xib it says an image is on the button but it doesn't appear. Any ideas why?
iOS 6:
iOS 7:
For me, my problem was that the button type was set to System instead of Custom. They displayed fine in iOS 6.0 and iOS 6.1 Simulators, just not iOS 7.0 simulator. I'm not sure how this happened as I'm pretty sure it's the first time the project had been opened in Xcode 5 with iOS 7.0 sdk. I had three buttons, 1 showed fine because it was a Custom button, and the other two did not show their images, but could be pressed. Once set to Custom button types, all worked great, as expected.
I was able to get the images to appear after setting the tint color to clear and setting the image and background image to what I wanted. In Xcode 4 I didn't have to change any of that and I didn't have to set the background image, just the image.
yes it is iOS7 issue.
Set bottom margin of the image/label through autolayout then try this code in your viewDidLoad and this should work.
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)])
{
[self prefersStatusBarHidden];
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
}
else
{
// iOS 6
}

iOS Publishing to multiple ios version

I'm developing a iOS app for iOS 7, the UI reflects this iOS version. But, I want to publish to others iOS's, like 6 or 5 too.
So, I'll change my UI and the target iOS version. I have to save other project, with this modifications? How I'll publish the same app for differents iOS versions? Thanks and sorry for the stupid question, I didn't find anything about it.
You should do this within a single app and it will run on whichever versions you've allowed. Start by setting your deployment target to the oldest version you want to support.
By using constraints or basing UI dimensions on known constants, you can accomplish most tasks that are OS version dependent.
A big issue to handle is the differences in how the status bar and transparent bars in iOS 7 are displayed. If you're using Interface Builder, you can use the View inspector on the right-side bar in XCode to set iOS6/7 Deltas that are applied depending on the version being run. You can also preview the differences in IB by selecting the root view of your xib and opening Identity inspector. Under Interface Builder Document, change "View as" to the OS version you want to see.
If all else fails, you can test for the OS version in code to write custom code for a version.
For example:
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
//ios 6 code
} else {
//ios 7 code
}
In your app set the Deployment Target to iOS 5.
When it comes to UI have a read of this Apple Doc on iOS 7 transition guide.
Ones you have read that and understand it then you can move onto actually creating your UI.
When I have created my UI's based on iOS version I have a prepocessor macro set
#define IOS_VERSION() [[UIDevice currentDevice] systemVersion];
This is set in my ***-Prefix.pxh file so I can access it throughout my app.
Then I can check this with a simple if statement like so
if(IOS_VERSION => 7.0) {
// Do our iOS 7 stuff here
} else {
// Do everything else, you could add else if to check 6.0, 5.0 even 4.0
}
remember to wrapper some method calls in if statements as well. Like:
if([object respondsToSelector:#selector(setTitle:forState)]) {
// object being whatever object you are wanting to work on UIButton, UILabel, UIView.
// The reason for this is some methods will be in iOS 7 or even 6 but not in iOS 5
// so if you called them methods you will received unrecognised selector excpetion.
}
You can also do somethings using interface build see the link I have provided for how to on interface builder.
Your design will differ based on iOS version. If you run on iOS 7 it will have the new flat UI look whilst if you build on other iOS it will have the old look. When moving over to the new look there wasn't many differences that we had to fix in our apps but we did have to fix some things. I would recommend building for either iOS 5 and 6 first and then 7 or the other way get it right in one before moving on.
You should have only one app supporting all of these.
In your XCode Project setting there will be a setting called deployment traget. which should be the Min OS version that your app supports. In your case it will be 5.0.
Coming to UI and other feature changes. You should be doing these at run time based the current OS version. Make use of [[UIDevice currentDevice] systemVersion] You can load respective based on this version.

Can I set two different xib for the same UIVIewController for iOS6 and iOS7?

Can I set two different xibs for iOS6 and iOS7?
I can't make the same changes to the same xib file for both iOS, and I can't set everything in the code.
thanks
Yes, you can just use [[UIDevice currentDevice] systemVersion] as stated in this question's accepted answer: How to check iOS version?
Get the version and conditionally load the correct XIB accordingly.
The suggested Apple method to check the version on iOS is this one, it is also reported in the ios7 transitioning guide:
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
As you can see here

Resources