A latest iOS version update can cover ~85% of iPhone users which is significant compared to a newly released Android running just ~0.1% of devices. (@StatistaCharts collected on September 2018 - iOS 11 vs Android Pie). If your application matters for the rest ~15% of “genuine” iOS users, then you have to spend extra time to support.
Base SDK refers to the newest version of iOS that is capable of running your app. To check which base SDK you are building your app against, simply open your project file in Xcode and check the setting under Build Settings -> Architecture Make sure you selected ‘Latest iOS’ from the dropdown list, So you don’t have to worry about updating your base SDK when Apple releases a new version of iOS.
Linking against a framework that doesn’t exist in your deployment target will just cause the dynamic linker to crash your app. To solve this, you mark unsupported frameworks as 'Optional' in your project settings.
2. Unsupported Classes
Look for Sometimes you want to use a class that exists in your base SDK, but not in your deployment target. For instance UIBlurEffect introduced in iOS 8.0. To support iOS 7.0, simply handle with the condition :
3. Unsupported Methods.
Similar to unsupported classes, you might face few methods that exists in your base SDK, but not in your deployment target. This time you can use 'respondsToSelector(_:)' API - which will return Boolean value 'true' if the specified method exists. For instance, Car class instance will call autoPilot if 'autoPilot' method exists - else it uses 'manualDrive'.
var car = Vehicle()
if car.responds(to:"autoPilot") {
car.autoPilot()
}
else {
car.manualDrive()
}
4. Explicit iOS Version Checks - Availability attribute
We can check current running version of iOS as -
var systemVersion = UIDevice.current.systemVersion
With the help of system version we can bypass unsupported Classes, Structs, Enums, Enum Cases, Methods and Functions. But.. There is a better approach.
'@available' attributes can be placed directly above any declaration in your code, other than a stored variable. For instance :
For further referenceWhy does it matters ?
Giving uniform user experience irrespective of iOS version and device factors - will give bonus market space for the sales. Essentially it will boost your revenue and popularity of the application.Deployment Target vs Base SDK
Before heading to solution, we have to understand Xcode settings for Deployment Target and Base SDK. A deployment target refers to the oldest version of iOS that is capable of running your project. To change your deployment target, open up your project file in Xcode and check the setting under Build Settings -> Deployment.Base SDK refers to the newest version of iOS that is capable of running your app. To check which base SDK you are building your app against, simply open your project file in Xcode and check the setting under Build Settings -> Architecture Make sure you selected ‘Latest iOS’ from the dropdown list, So you don’t have to worry about updating your base SDK when Apple releases a new version of iOS.
How to shine the aged iOS version ?
1. Unsupported Frameworks :Linking against a framework that doesn’t exist in your deployment target will just cause the dynamic linker to crash your app. To solve this, you mark unsupported frameworks as 'Optional' in your project settings.
2. Unsupported Classes
Look for Sometimes you want to use a class that exists in your base SDK, but not in your deployment target. For instance UIBlurEffect introduced in iOS 8.0. To support iOS 7.0, simply handle with the condition :
if NSClassFromString("UIBlurEffect") {
let blur = UIBlurEffect(...)
//use ‘blur’ for rest of the code
}
else {
//Find alternative class that gives blur effect
}
NSClassFromString returns ‘nil’ if the specified class doesn’t exists in the running iOS version or else it will return the class name.let blur = UIBlurEffect(...)
//use ‘blur’ for rest of the code
}
else {
//Find alternative class that gives blur effect
}
3. Unsupported Methods.
Similar to unsupported classes, you might face few methods that exists in your base SDK, but not in your deployment target. This time you can use 'respondsToSelector(_:)' API - which will return Boolean value 'true' if the specified method exists. For instance, Car class instance will call autoPilot if 'autoPilot' method exists - else it uses 'manualDrive'.
var car = Vehicle()
if car.responds(to:"autoPilot") {
car.autoPilot()
}
else {
car.manualDrive()
}
4. Explicit iOS Version Checks - Availability attribute
We can check current running version of iOS as -
var systemVersion = UIDevice.current.systemVersion
With the help of system version we can bypass unsupported Classes, Structs, Enums, Enum Cases, Methods and Functions. But.. There is a better approach.
'@available' attributes can be placed directly above any declaration in your code, other than a stored variable. For instance :
if #available(iOS 9.0, *) {
// use the feature only available in iOS 9
// use the feature only available in iOS 9
// for ex. UIStackView }
else {
// or use some work around
else {
// or use some work around
}
medium.com
raywenderlich.com