Change UIAlertView to UIAlertController of app to get updated to iOS 8 - ios7

I have to update to iOS 8 some apps developed for iOS 7. After UIAlertView got deprecated on iOS 8. My question is:
Is it neccesary to check the iOS version, and show a UIAlertController rather than a UIAlertView?
Or can I leave the implementation of UIAlertView? Will iOS can use it for some years more? Since its deprecated.
Thanks

Nothing is "necessary", but for best compatibility going both backwards into the past and forwards into the future it is obviously best to adopt the new technology in iOS 8 and abandon the deprecated technology. So if you want your app to work both in iOS 7 and iOS 8, the broadest possible coverage would require that, yes, you use UIAlertView in iOS 7 and UIAlertController in iOS 8.

Related

iOS how can I use storyboard elements that don't exist in earlier versions of iOS?

I have a project originally targeting iOS7 using a storyboard. I've added a UIStackView to a view controller and get an error that "UIStackView before iOS 9.0". The build fails because of this error.
How can I keep my project as iOS7, while conditionally including newer storyboard elements from iOS9 if device supports them?
I already have conditional code in the project that only runs on iOS8+, but how can I do something similar with a storyboard?
The class UIStackView (and its software) is provided by iOS 9, but is not provided by iOS 8 or 7. When the app tries to instantiate an object from the storyboard in iOS 8, it will fail because it cannot find the class.
The only ways around this:
have different storyboards for different iOS vesions
build a custom class that does the same thing. Then you can use it in the older versions of the iOS. You might find open source libraries that already do this for the class you want.

UIActionSheet causes application to crash with XCode5 on iOS 8

In testing my application to see how it will work with an XCode 5 build on iOS 8. The biggest problem I have is that all of our confirmation dialogs cause the application to crash. If I build it on XCode 6 beta, it doesn't crash but the popup is not centered in the window.
Here is the code. It calls the showInView, but does not return. So my question is, am I doing something wrong? If not, what changed, and how do I fix it?
The NSException is being thrown on the showInView
-- reason NSString * #"Application tried to present modally an active controller <_UIAlertShimPresentingViewController:
0x7fab69793330>." 0x00007fab69747ec0
UIActionSheet* confirmAction = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(#"SiteUpToDate", nil)
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:NSLocalizedString(#"Yes", nil)
otherButtonTitles:NSLocalizedString(#"No", nil), nil];
[confirmAction showInView:self.view];
[confirmAction release];
Update: I found that this was an issue with the Beta OS & Beta XCode. As soon as iOS 8 was officially released, our issues went away.
I also had the same problem. i used ShowFromBarButtonItem function instead of ShowInView Function.
[organizeActionSheet showFromBarButtonItem:btnAction animated:NO];
if use ShowFromRect or showFromBarButtonItem runtime exception will not come. i think it is a bug of IOS8 Beta, when i use ShowInView Runtime exception is coming.
This bug is not happening in IOS Beta 4..
I do get some warning messages in the debug window when built using Xcode 5.1, but the action sheet does appear. In iOS 8 beta 4, it appears as a small pop-up window outside of the view (at the side), whereas in iOS 7, it used to appear as buttons that slid up from the bottom of the view.
according to this https://developer.apple.com/library/ios/documentation/Uikit/reference/UIActionSheet_Class/index.html
UIActionSheet is deprecated, you should use UIAlertController instead of UIActionSheet.
Answer is from here:
How to do "actionSheet showFromRect" in iOS 8?
Something that might fix your problem. We were running into a lot of issues when presenting UIActionSheets directly after dismiss any kind of modal view controller. If this is indeed the case, you need to call the action sheet 'presentInView...' methods only AFTER the first modal has gone away.

Tabbar icons not showing selected state in ios7

I'm currently in the process of building an app in XCode 4.6 with iOS 6 as the minimum target. As far as I'm aware this app should work in iOS7 devices, however the selected icon stays on my unselected icon when changing tabs. iOS6 devices work absolutely fine
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Home" image:[UIImage imageNamed:#"Tab_home.png"] tag:0];
[[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:#"Tab_homeselected"] withFinishedUnselectedImage:[UIImage imageNamed:#"Tab_home.png"]];
Now looking through Apple docs/Stackoverflow I've seen a few posts saying that these methods are deprecated in iOS7 which is fair enough. However I'm not using XCode 5 or building for iOS7. I'm building for iOS6 and as far as I'm aware Apple state that old apps should work.
Does anyone know how I can get around this? I've tried the suggestion here issue with ios7 tabbar controller
but I get build errors as UIImageRenderingModeAlwaysOriginal is not defined. Is it a case of somehow using respondsToSelector and performSelector for this to do something similar to
[[UITabBarItem alloc] initWithTitle:#"Music" image:musicImage selectedImage:musicImageSel];
as outlined at UITabBar not showing selected item images in ios 7
The build errors for UIImageRenderingModeAlwaysOrigina, is because it was only introduced in iOS SDK 7.0 so if you are building for iOS 6 you cannot use this as it is undefined (not included in SDK 6.x), If you are building solely for iOS 6 it will work on iOS 7 devices but you can only use code that is present in the iOS 6 SDK (which you are using). I wouldn't worry about Apple docs/Stackoverflow saying things are depreciated, you only need append your code if your compiler (Xcode) says it's depreciated for your deployment target (in your case 6.x).

How to use NSLayoutConstraint in iOS 6?

My app should support both iPhone resolutions (5 and older) using iOS 5 and iOS 6. When I use autolayouts in IB, on iOS 5 app crashes like this: link
So, I am trying to use NSLayoutConstraint in code, but unsuccessfully yet.
Subquestions:
I am adding constraints in viewDidLoad method, but is it correct?
Does updateViewConstraints invoke by framework? I have never seen that it was invoked.
I tried to use examples from apple's docs, but it was without effect to view.
Anybody knows how to do it?
PS: I know it's possible to make it manually by setting frames, but I would like to use NSLayoutConstraints.
UDP: Yes, I know, that's why i use NSLayoutConstraint in code. I can make condition for determining iOS version. The question is about iOS6.
The AutoLayout feature is only compatible with iOS6 and is not supported in iOS5. Thus the crash
If you intend your app to be compatible with iOS5, you can't use AutoLayout in your XIB files.
You can only use older methods, like the AutoResizingMask for example (which is often sufficient for most cases anyway).

Convert lat long to Place Name

I want to convert the latitude - longitude to Address(Place Name).
I think it can be done using CLGeocoder on iOS 5.0 and MKReverseGeocoder (Depricated in iOS 5.0) on iOS < 5.0.
My application need to support from iOS 4.0 onwards.
Can anybody suggest a way to implement this.
Thanks in advance.
The fact that the API is deprecated does not mean that you cannot use it on iOS 5. It is still going to work, but may be removed in a future version without warning. So to keep the compatibility, you could perform a check if the CLGeocoder class is available and use the appropriate implementation:
Class clGeocoderClass = NSClassFromString(#"CLGeocoder");
if (clGeocoderClass) {
// iOS 5. Use CLGeocoder
} else {
// iOS prior to 5. Use MKReverseGeocoder.
}
So you won't run into any problems if MKReverseGeocoder is removed in the future, because the CLGeocoder class will be preferred. Devices running iOS versions prior to 5 are unavoidably going to fall back to MKReverseGeocoder anyway, which is no problem on old versions.