前言
iOS 開發者 最憋屈的就是UI 布局慢,一直以來沒有實時預覽功能,雖然swiftUI 早就支持了,但是目前主流還是使用UIKit在布局,iOS 17 蘋果推出了 #Preview 可以支持UIKit 實時預覽,但是僅僅是 iOS 17,老項目怎么辦呢?于是就有了這篇 老項目適配 #Preview 預覽 的文章,從新建 Targets 是正文開始,前面的是我在探索過程中的踩坑記錄。
環境
MacOS: 15.1
Apple: M4
Xcode: 16.1
一、AlipaySDK 報錯
錯誤日志
PREVIEW UPDATE ERROR:
FailedToLaunchAppError: Failed to launch com.xxx.xxx
XOJITError: x86_64 slice of /Users/xxx/Documents/YLProject/poetry/Pods/AlipaySDK-iOS/AlipaySDK.framework/AlipaySDK does not contain an archive
解決
- 更新 Podfile 配置:
post_install do |installer|installer.pods_project.targets.each do |target|target.build_configurations.each do |config|# Needed for building for simulator on M1 Macsconfig.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'endend
end
- 清理并重新安裝依賴
pod deintegrate
pod install
二、ProjectWidgetExtension 小組件中報錯
錯誤日志
Could not find module ‘WebPKit’ for target ‘arm64-apple-ios-simulator’; found: x86_64-apple-ios-simulator, at: /Users/liyanhong/Library/Developer/Xcode/DerivedData/poetry-fgnfhoqfwdsbnpaudqkcloqdigxt/Index.noindex/Build/Products/Debug-iphonesimulator/WebPKit/WebPKit.framework/Modules/WebPKit.swiftmodule
解決
在 ProjectWidgetExtension 的 Build Settings 中,手動排除模擬器架構:
1. 打開 Build Settings。
2. 搜索 Excluded Architectures。
3. 在 Any iOS Simulator SDK 中添加 arm64。