Conditionally import a framework (such as Speech) based on iOS Version in Swift?
You can make the Framework optional (details and image from Ray Wenderlicht):
This, combined with your use of @available, should prevent the system from trying to load it on the devices where it is not available.
Import Framework Based on Current Target
In your target's build settings, Swift Compiler - Custom Flags -> Other Swift Flags, add a flag for one target, say -DTargetX
Then…
#if TargetX
import FrameworkX
#else
import FrameworkY
#endif
How do you selectively import a framework in Swift?
For Swift <= 4.0 you can use the os()
configuration test function:
#if os(iOS)
import CoreTelephony
#endif
You'll have to wrap code that uses CoreTelephony
as well.
All available tests for os()
are: macOS
, iOS
, watchOS
, tvOS
, Linux
, Windows
, and FreeBSD
.
For Swift >= 4.1 you can also use canImport()
:
#if canImport(CoreTelephony)
import CoreTelephony
#endif
iOS - Link a framework with higher deployment target than my project's
Think about it. The framework could be using features, libraries available in the later deployment of iOS, that aren't in the deployment of iOS you are using. So yes you'll have to change your app's deployment target if you want to use this framework.
Although you can conditionally import a framework based on iOS version Conditionally import a framework (such as Speech) based on iOS Version in Swift? but then of course you'll need a solution for the versions of iOS which the framework doesn't work for.
Related Topics
Nsinternalinconsistencyexception, Reason: Could Not Load Nib in Bundle
Union Uibezierpaths Rather Than Apend Path
Swiftui - Animations Triggered Inside a View That's in a List Doesn't Animate the List as Well
Swift - Compressing Video Files
App Transport Security Has Blocked a Cleartext Http Resource
How to Draw a Circle Path with Color Gradient Stroke
Create PDF with Multiple Pages
iOS Getting Location Updates When App Terminated Without Using Significantchange
How to Copy SQLite Database When Application Is Launched in iOS
Firebase Chat Push Notifications
Swift Force-Unwrapping Exception Not Propagated
What Is Most Common and Correct Practice to Get a Cgfloat from an Nsnumber
iPhone Uitableview. How Do Turn on the Single Letter Alphabetical List Like the Music App
Face Recognition on the Iphone
Disable Bitcode for Project and Cocoapods Dependencies with Xcode 7
Custom Uifont Baseline Shifted
Using Uipageviewcontroller with Swift and Multiple View Controllers