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).
Related
I see this type of action sheet on iOS devices using the Google Drive application.
I want to know if it is already supported on iOS SDK or if it is a custom UI?
If it is already a standard component, what's name of it?
It was called UIActionSheet before iOS8 and after you can find this UI component under the UIAlerController. You can use this component to make some UI like this but development target should be more that iOS8.
You can check here for documentation.
I'm not aware of any custom components, but it looks to me like a standard UIAlertController with a ActionSheet style. As the alert controller extends UIViewController, you may add subviews to it.
The screenshots indicate that they added a UITableView as a subview to the alert controller:
Ok, got it. It's only for iOS 8 and later. It's named UIDocumentPickerExtensionViewController.
I was wondering whether it is possible / how it is possible to code a class so it can be run on different iOS versions in Objective-C. For example the VisualEffectView is only available in iOS8 and after. Is it possible to declare a VisualEffectView if iOS >= 8 and UIView if not? If so can this be done within a header file?
I want to create an alert box to appear on top of a view controller when a save completes or error occurs. Depending on the iOS version it would be nice if a fancy blurry view is used or just a flat UIView.
In an if statement, use NSClassFromString. You'll discover immediately that UIVisualEffectView doesn't exist when it returns nil, and thus you can take one branch if it exists and another if it doesn't:
if (!NSClassFromString(#"UIVisualEffectView")) {
// ... use UIView ...
} else {
// ... use UIViewVisualEffectView ... {
}
As of iOS 5 you can the following syntax.
if ([UIVisualEffectView class]) {
// Create and use a UIVisualEffectView
}
This will occasionally bite you, NSMapTable is available in iOS versions prior to iOS 6, but was only "officially" available in iOS 6. When attempting to use it in iOS 5 there was some sporadic undocumented behavior.
As many have suggested, you can use the NSClassFromString function to find out at run time if the OS version has the class. If it doesn't (that is iOS 7 devices) and you still want live blurring, I'd recommend LiveFrost.
Just starting out with iOS developing in Swift so I'm not certain how to call this thing.
What I'm trying to accomplish is a choice like the image below.
What is it called and where do I start?
UIActionSheet is what you are searching for.
Be careful because it's deprecated since iOS 8 but the reference links to the replacement as well.
in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet.
I am trying to, when a button is pressed, a small menu comes up, like NSRunAlertPanel in Cocoa. It is like in iOS, when you press reset, it gives you options to continue, or go back. Image:
How do I do this?
As noted above, the answer to this is UIActionSheet in iOS < 8 and UIAlertController for iOS >= 8. Easier to grab a library that's abstracted that away for you; these look good.
Objective-C: MSAlertController for iOS
Swift: SimpleAlert for 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).