UIActionSheet vs UIAlertController - iPad - ios

Do we have to work with the UIAlertController in the iOS8 or could we still work with the UIActionSheet?
I don't want massive changes in our code for iOS 8 compatibility, but I'm encountering several issues when working with the UIActionSheet on iPad.
For example I'm getting this exception when using the UIActionSheet:
UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7c57bf90>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.
I understand that it is preferred to work with the new UIAlertController, but is there any workaround for this in order to continue to work with the UIActionSheet?
Also in places that the UIActionSheet actually shows (with no exception) it contains an arrow + it is not centred like before (iOS7) - I'm using the showInView (also tried to work with showFromRect but got the same results).

From the documentation its clear that UIActionSheet is deprecated. Means that you can still use it but in future in can fail or will be removed completely.
I highly recommend you to update to UIAlertController.
The exception you got on iPad is clear. As the UIAlertController with style actionSheet needs sourceView (the view from the actual controller will be presented) as its no more full screen (as its on iPhone).

Related

UIActionSheet on iOS8

I have an app that connects to Chromecast - I referenced from the Chromecast Sample Code which uses UIActionSheet to display the list of Chromecast devices I can connect to.
This was working well for my app which has been running with BaseSDK=iOS6.1. Recently I tried to upgrade to BaseSDK=iOS8.1 and the UIActionSheet doesn't show anymore.
I understand that it has been deprecated in iOS8, but does that mean it wont work anymore? I thought deprecated methods typically take some time to "phase out".
So my main questions are:-
Can I still use only UIActionSheet? Is it just a matter of view hierarchies being changed which is why my ActionSheet is not showing anymore?
If the answer to question 1 is NO, what can I do to allow compatibility with both iOS7 and iOS8.
With iOS8.1 sdk UIActionSheet is deprecated, you should do runtime check to see if it is available and act accordingly using correct class:
if objc_getClass("UIAlertController") != nil {
// UIAlertController is available use it with style UIAlertControllerStyleActionSheet
} else {
// no UIAlertController use regular old action sheet
}
For iOS8 and you above, you will have to migrate to the UIAlertController for both the action sheet and alert pop up.
In all honesty, I find the new API easier to work with. There is a little more here (in Swift, but not any harder in Objective C).

Why does [uiActionSheet showInView:self.view.window] "hang" in iOS8?

I have an app in AppStore (iPhone-only, iOS3.1+ compatible, 2011 Xcode 3 compile) that has been working amazingly fine for three years untouched. Recently however it started "freezing" on iOS8 under certain conditions. That happens in couple of places, both when UIActionSheet is to be shown. Nothing pops on screen, the app does not crash but instead stays irresponsive to any taps; nothing in system console. The only way "out" after that happens is to kill the app manually from the task switcher and start it again.
I believe the reason is the way i show the UIActionSheet, which was as simple as these 3 lines, from a UIViewController method:
UIActionSheet* actSheet = [[UIActionSheet alloc] initWithTitle:#"Could not connect to [...]" delegate:nil cancelButtonTitle:#"OK" destructiveButtonTitle:nil otherButtonTitles:nil];
[actSheet showInView:self.view.window];
[actSheet autorelease];
I think the reason is the use of self.view.window, which is UIWindow (which inherits UIView, naturally) - and that just using self.view should solve the issue (i read here https://stackoverflow.com/a/26171717/226086 that showInView: now only works with UIView with UIViewController attached). Why did i use self.view.window in the first place - probably i read about this issue with cancel button alignment.
However, i am unable to reproduce the problem when compiling my app in Xcode 6 - and Xcode 3 cannot debug iOS8. And my conundrum is how do i exorcise a bug i cannot reproduce to verify.
Do you have insight on the changed behavior of UIActionSheet, what is causing the hanging in iOS8?
PS. Please don't tell me "UIActionSheet is deprecated in iOS8, use UIAlertController instead". That is an incorrect answer: "deprecated" does not mean UIActionSheet does not work in iOS8 no more - it is just discouraged for new code and may be dropped in next versions. But i want to keep compatibility with iOS5+ (my reasoning akin to this) so i rather fix the use of it - which i mention above seems fishy with showInView:self.view.window.
This is a long shot, but there is an issue in iOS8 related to rotation not working when the following line is left in your app delegate didFinishLaunchingWithOptions: method. The line is a hangover from pre iOS8 xcode generation and relates to the window for the application. Only affects iOS8. Previous versions all work fine.
The line is:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
This is nolonger needed and should be commented out. Given you are using self.view.window perhaps there is some side effect with UIActionSheet as well.
As I say, a long shot but seems a coincidence that your having an issue in iOS8 only related to using a window view.
I dont think you should have an issue using UIAlertController, as far as support for previouis versions of iOS are concerned you can try creating instance of UIAlertController using [[UIAlertController alloc] init] if it returns nil(which it will for older versions of iOS) you can use UIAlertSheet you are using currently.

iOS5 Custom Window rotation issue

So I'm creating and showing a custom window in my iOS app because I'm writing a dynamic alert view that also functions like a growl/toast alert. It works AWESOMELY in ios6 (Hopefully I can open source this baby and you can all check it out)
But anyway, when I run this in ios5, the window that my alerts exist on doesn't seem to rotate with the device/simulator. No matter what, my custom window stays in portrait mode.
The UIWindow is just a UIView subclass, so there's no nice 'shouldRotate' delegate method.
I'm kinda stumped on why this is happening in ios5 but not 6. Any help would be GREATLY appreciated ^_^
My window has a rootviewcontroller, which I completely forgot about. I just needed to implement
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
}
To get it to work.
:-D
It's usually not recommended two use multiple instances of UIWindow in one iOS app. The only valid reason to do so is to support external screens. You should use a UIView instead, ideally managed by a UIViewController.
I assume, (since you didn't provide any code, I can only assume) the reason why your window doesn't 'rotate' is, that it's simply not getting any notifications about device rotation. Only the keyWindow receives them by default.
I would highly recommend to redesign your app to use a properly managed UIView instead. If you desperately don't want that for some reason, you would have to register your instance of UIWindow to receive the UIDeviceOrientationDidChangeNotification and then (in the handler) evaluate what the new orientation is and change the window's frame accordingly (plus maybe other things that need to be done in response to the orientation change)

Issue dismissing/ re-presenting MFMessageComposeViewController with iOS6 but fine with iOS5

I'm presenting an MFMessageComposeViewController which works fine with iOS4 and iOS 5 but has problems with iOS6.
The view is presented ok but if its dismissed and then represented it doesn't display correctly - only the To: line is displayed, the body and keyboard are missing. (Sorry I can't post a screen shot at the moment as XCode crashes when I take a shot, I'm downloading an older version of XCode as I type).
Stepping through the code in the debugger I noticed that the problem may originate earlier than the re-presenting - I noticed than when dismissViewControllerAnimated: gets called the entire view does not get dismissed immediately, rather it is the message body and keyboard that gets dismissed leaving behind the To:, the same thing that is displayed when the view is re-presented.
It might be easier to describe with screenshot, I'll post some shortly.
I'm using presentViewController: and dismissViewControllerAnimated: to present/dismiss the MFMessageComposeViewController.
+++ UPDATE +++
I've found the problem can be solved if instead of using the same MFMessageComposeViewController object to re-present the view I first delete it and then create a new one.
That seems a little inefficient though, and it should not be necessary I'd have though, like i mentioned it worked on iOS5.
In iOS 6 apple introduced a new feature "remote view controller". Some external view controllers are no longer part of your app, and the messaging controller is one of them.
I guess that is the problem in your case.
you can read more about it there: http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/

UITapGestureRecognizer from Objects library in storyboard on a view which is inside a tab bar controller

I added a UITapGestureRecognizer to a view which is inside a tab bar controller and when I switch to the tab which contains the view with the UITapGestureRecognizer, I get a crash with the message -
-[__NSCFString setView:]: unrecognized selector sent to instance 0x2ae8d0
I am using Xcode 4.3
i had this same trouble on iOS5 only with an app targeted to iOS 5 and iOS 6 and a gesture recognizer on the last tab. our code also has very similar gesture-recognizers that are loaded for modal dialogs or pushed view controllers for other tabs. so it was only gesture-recognizers in a tab that was not the first tab, and only in the rootViewController for that tab.
as Arunabh Das ended up doing, it would seem the only answer is really to add the UIGestureRecognizers in code. there is a thread at Ray Wenderlich's website (which is a decent site containing some good iOS tips) , which, summarized, notes that there appears to be a bug in iOS5, starting with the beta versions, never fixed in the final, and containing a code-snippet that shows how to put the gesture-recognizers in code if you want them.

Resources