dyld:当应用程序使用 @available(iOS 13.0, *) 在 iOS 12 上运行时,库未加载 SwiftUI [英] dyld: Library not loaded SwiftUI when app runs on iOS 12 using @available(iOS 13.0, *)
问题描述
我决定在我的应用中使用 SwiftUI 实现一些视图.该应用向后兼容 iOS 12.
I decided to implement a few views using SwiftUI in my app. The app is backward compatible with iOS 12.
一切正常,直到我在 iOS 12 设备上运行它.该应用程序立即崩溃,我收到的警告说无法加载 SwiftUI.
Everything works perfectly until I run it on an iOS 12 device. The app crashes immediately and the warning I get says SwiftUI cannot be loaded.
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 上完美运行
I'm using @available(iOS 13.0, *) in all the correct places and there are no compiler warnings and the app runs perfectly on iOS 13
我怎样才能让它在 iOS 12 上运行?
How can I get this to work for iOS 12?
推荐答案
原来这是一个已知问题,Apple 引入了一个新的构建设置标志来处理它
Turns out this is a known issue and apple introduced a new build setting flag to handle it
在 Swift 包中包含 SwiftUI 的应用程序可能无法运行iOS 13 之前的 iOS 版本.(53706729)
Apps containing SwiftUI inside a Swift package might not run on versions of iOS earlier than iOS 13. (53706729)
解决方法:
当回部署到不包含 SwiftUI 框架的操作系统时,将 -weak_framework SwiftUI 标志添加到其他链接器标志设置在构建设置"选项卡中.有关更多信息,请参阅框架和弱链接有关弱链接框架的信息.此解决方法不适用使用导入 SwiftUI 的动态链接的 Swift 包时.
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
添加到 Other Linker Flags
修复了我的问题
Adding -weak_framework SwiftUI
to Other Linker Flags
fixed my issue
这篇关于dyld:当应用程序使用 @available(iOS 13.0, *) 在 iOS 12 上运行时,库未加载 SwiftUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!