I'm using home screen quick actions that's only supported in IOS9
.
Using the constant UIApplicationLaunchOptionsShortcutItemKey
will crash if used in IOS8
.
What is the correct way to check if quick actions is supported?
One way is to check for IOS9
through systemVersion but I'm hoping there is a better way.
[[UIDevice currentDevice] systemVersion]
In objective C you can check to see if a class exists. Say something like
if([UIApplicationShortcutItem class]){
//Handle shortcut launch
}
I think in case of Swift
the best way for checking the API
availability is Automatic operating system API availability checking
that's new feature released with iOS9
and Swift2
if #available(iOS 9, *) {
// use UIApplicationLaunchOptionsShortcutItemKey
} else {
// no available
}
#available
is going to check whether are we using iOS 9 or later, or any other unknown platforms like watchOS
so the *
is also here.
If your code is inside a function then you can use #available
with guard
like this.
guard #available(iOS 9, *) else {
return
}
Mark your methods and class as well like
@available(iOS 9, *)
func useMyStackView() {
// use UIStackView
}
@available
works similarly to #available
so If your deployment target is iOS7
or less than 9, you can't call that useMyStackView()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With