Hello. iOS 15 and its version of Swift had an issue with applying class level annotations, such as @available to the members of its class. When we attempt to use our Objective-C library to get the class, if there are things inside the class not available on iOS 15, then the call to objc_getClass
crashes with EXC_BAD_ACCESS. This appears to have been fixed on iOS 16 and newer, however, as we still support iOS 15, is there a better workaround than having to annotate every needed member of the class with @available, instead of being able to use the class level annotation?
iOS 15 crash with objc_getClass
I’ll need more details to offer any advice here. Let’s start with the basics: Please post an Apple crash report of the problem, per the advice in Posting a Crash Report.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
The text version of the crash report should be attached. There are two relevant snippets of code for this crash to happen:
@available(iOS 16.0, *)
@MainActor
final class ScanViewModel {
var scanTextType: DataScannerViewController.TextContentType?
@Published var recognizedItems: [RecognizedItem] = []
}
In this block, we use the @available annotation to try and stop things that don't exist in iOS 15 from being accessed. Later, in instrumentation:
unsigned int classNameCount = 0;
const char **classNames = objc_copyClassNamesForImage(mainImageName, &classNameCount);
for (NSUInteger i = 0; i < classNameCount; i++) {
Class cls = objc_getClass(classNames[i]);
NRMA__processClass(cls, results, parents);
}
free(classNames);
This crashes on the call to objc_getClass()
when passed the class which has the @available annotation.
What I am asking is if there is a workaround for this bug in iOS 15 (this doesn't happen on iOS 16 and above)? Thank you.
Hi. Is there a more convenient workaround, or something that can perhaps be done when calling objc_getClass to avoid this crash, or am I doomed to have to annotate every aspect of the class until iOS 15 goes out of style?