I’ve added an app clip with iOS model 17.4 to my major app of goal 12.0. I’m sharing code from the primary app with the app clip by deciding on each targets underneath the file’s goal membership.
In some locations, this causes points with deprecated code. Eg with this line:
“notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), title: NSNotification.Title.UIKeyboardWillHide, object: nil)”
Since together with the app clip with the upper iOS model as a goal for the file that incorporates the code, I get a compile error:
“‘UIKeyboardWillHide’ has been renamed to ‘UIResponder.keyboardWillHideNotification’, Change ‘UIKeyboardWillHide’ with ‘UIResponder.keyboardWillHideNotification'”
I assumed utilizing #availble would resolve this:
if #obtainable(iOS 13.0, *) {
// For iOS 13.0 and later
notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), title: UIResponder.keyboardWillHideNotification, object: nil)
} else {
// For iOS 12.0
notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), title: NSNotification.Title.UIKeyboardWillHide, object: nil)
}
However I’m nonetheless getting compile errors. If the primary app scheme is chosen, the errors happen within the first (if) assertion, if the app clip is chosen the errors happen within the second (else) assertion.
I attempted utilizing
#if APPCLIP
notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), title: UIResponder.keyboardWillHideNotification, object: nil)
#else
notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), title: NSNotification.Title.UIKeyboardWillHide, object: nil)
#endif
However when the app clip scheme is chosen the errors stay within the else assertion.
I can clearly have two information, one for the app clip and one for the primary app, however this isn’t supreme as it will imply if code adjustments must made sooner or later they must be made twice.
Does anybody have a cleaner answer?