There are some new environment variable I need to use, for example
@Environment(\.requestReview) var requestReview // StoreKit
But my app needs to support older iOS. How do I "wrap" around this environment variable while not using iOS 16?
CodePudding user response:
We need to annotate view holding that, like
@available(iOS 16, *)
struct StoreKitView: View {
@Environment(\.requestReview) var requestReview
// ...
CodePudding user response:
You can create your own extension for EnvironmentValues
& in it do the check:
extension EnvironmentValues {
var requestReviewOld: SomeType? {
get {
if #available(iOS 16.0, *) {
self.requestReview
}else {
nil
}
}
set {
if #available(iOS 16.0, *) {
self.requestReview = newValue
}
}
}
}