简体   繁体   中英

How to detect SwiftUI usage programmatically in an iOS application

I am working on a library for iOS, and i need to know if the application using the library is running SwiftUI or not so that i can handle things appropriately.

Is there a way to find this out programmatically in Objective-C?

In the end i did this.

  1. Get the root or key window of the application.

  2. Check if it's class name contains "UIHostingController"

  3. Also nil check for this: NSClassFromString(@"SwiftUI._UIGraphicsView")

You could also check for other swift ui classes but this has covered all cases so far.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM