Reputation:
How I can let's start the following method only if is >= 8.0 ? It's in the TabBarController class.
let floatVersion = (UIDevice.currentDevice().systemVersion as NSString).floatValue
func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
// if ( floatVersion >= 8.0) {
let transitioningObject: TransitioningObject = TransitioningObject()
transitioningObject.tabBarController = self
return transitioningObject
//}
}
Upvotes: 0
Views: 79
Reputation: 1108
let iosVersion = (UIDevice.currentDevice().systemVersion as NSString).floatValue
func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
switch iosVersion.compare("8.0.0", options: NSStringCompareOptions.NumericSearch)
{
case .OrderedSame, .OrderedDescending:
//iOS>=8.0.0
let transitioningObject: TransitioningObject = TransitioningObject()
transitioningObject.tabBarController = self
return transitioningObject
case .OrderedAscending:
//iOS<8.0.0
return nil
}
}
Upvotes: 0
Reputation: 10296
Since your method return optional UIViewControllerAnimatedTransitioning you can return nil if version is lower then 8.0
func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if ( floatVersion >= 8.0) {
let transitioningObject: TransitioningObject = TransitioningObject()
transitioningObject.tabBarController = self
return transitioningObject
}else{
return nil
}
}
Upvotes: 2
Reputation: 277
The best way to do this, assuming your code may run on something below iOS 8 (which only seems reasonable, given your question) is to compare it to -[UIDevice systemVersion]
. Check out the following Swift code:
switch UIDevice.currentDevice().systemVersion.compare("8.0.0", options: NSStringCompareOptions.NumericSearch) {
case .OrderedSame, .OrderedDescending:
println("iOS >= 8.0")
case .OrderedAscending:
println("iOS < 8.0")
}
The above was borrowed from NSHipster. There's a better way to do this if your code won't run on a device running below iOS 8 (probably only really useful once iOS 9 comes around). See here for further information.
Upvotes: 0
Reputation: 3780
Check this response for verifying system version.
You're on the right track already, just handle the if
as you do for iOS >= 8.0
, and else call an iOS7 alternative and return nil
let floatVersion = (UIDevice.currentDevice().systemVersion as NSString).floatValue
func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if ( floatVersion >= 8.0) {
let transitioningObject: TransitioningObject = TransitioningObject()
transitioningObject.tabBarController = self
return transitioningObject
}else {
//do something else here if it's iOS7 or earlier?
}
return nil
}
Upvotes: 1