我决定在我的应用程序中使用 SwiftUI 实现一些 View 。该应用程序向后兼容 iOS 12。
一切都很完美,直到我在 iOS 12 设备上运行它。应用程序立即崩溃,我收到的警告说无法加载 SwiftUI。
dyld: Library not loaded: /System/Library/Frameworks/SwiftUI.framework/SwiftUI
Referenced from: /var/containers/Bundle/Application/MyApp.app/MyApp
Reason: image not found
我在所有正确的位置使用 @available(iOS 13.0, *),并且没有编译器警告,并且应用程序在 iOS 13 上完美运行
如何让它适用于 iOS 12?
最佳答案
事实证明这是一个已知问题,苹果引入了一个新的build设置标志来处理它
Apps containing SwiftUI inside a Swift package might not run on versions of iOS earlier than iOS 13. (53706729)
Workaround:
When back-deploying to an OS which doesn't contain the SwiftUI framework, add the -weak_framework SwiftUI flag to the Other Linker Flags setting in the Build Settings tab. See Frameworks and Weak Linking for more information on weak linking a framework. This workaround doesn't apply when using dynamically linked Swift packages which import SwiftUI.
将 -weak_framework SwiftUI
添加到其他链接器标志
解决了我的问题
关于ios - 迪尔德 : Library not loaded SwiftUI when app runs on iOS 12 using @available(iOS 13. 0, *),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57907817/