iOS 16 適配問題記錄

語言: CN / TW / HK

1.升級xcode 14 之後首先就是運行舊項目奔潰

運行報錯運行遇到的報錯 “error: Signing for “XX” requires a development team.”

推薦解決辦法 直接pod 配置

image.png

post_install do |installer| installer.pods_project.targets.each do |target| if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" target.build_configurations.each do |config| config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' end end end end

2.xcode14打出來的包多了一些系統庫在iOS 12.2 一下的版本直接奔潰

xcode 14 導出的新包後,打開就崩潰,但是在系統版本高的手機上就沒有問題iOS 12.2 版本一下的都有問題。

image.png

搜索後發現,開發者社區中有此問題的記錄,xcode14:Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib,解決方案是:

If you are building your app with Xcode 14 or Xcode 14.0.1, your app will crash on older OS versions, including while building and testing directly from Xcode, as well as after submitting the app to the App Store. The OS versions affected include iOS 11 - 12.1, macOS 10.13 - 10.14.3, as well as watchOS and tvOS versions from the same time frame. To work around the crash when building with Xcode 14, **add -Wl,-weak-lswiftCoreGraphics (substituting other library names for swiftCoreGraphics if appropriate for your crash) to the Other Linker Flags build setting**.

然而需要注意的是,假如項目有多個Target,如果添加在Target中,就要針對每個Target都要添加一次,很是麻煩,所以可以直接在PROJECT下的Build Settings中添加。

在項目中添加了-Wl,-weak-lswiftCoreGraphicsOther Linker Flags之後

假如説添加完之後還是會有報錯

image.png

仔細看了之後,發現報錯中提示的FSPagerView,是CocoaPods三方庫,所以找到對應的第三方庫,然後在對應庫的Build Settings中找到Other Linker Flags,然後添加-Wl,-weak-lswiftCoreGraphics,再運行,發現還是報錯,但是換了另一個三方庫。

所以有沒有可能,在Podfilepost_install添加設置,統一一次性給所有三方庫加這個編譯設置。當然可以,設置如下:

post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['OTHER_LDFLAGS'] = '-Wl,-weak-lswiftCoreGraphics' end end end

然後編譯,發現報錯,因為項目中有些庫沒有用到swiftCoreGraphics,比如OC的三方庫,或者非UI的庫,所以還是要改,需要區分添加。針對項目中Swift類型的UI相關的庫,添加這個編譯選項,其他的不添加,最終示例如下:

``` need_otherlinkerflags_frameworks = ['FSPagerView', 'HandyJSON', 'IQKeyboardManagerSwift', 'JXSegmentedView', 'KDCircularProgress', 'Kingfisher', 'RxSwift', 'PKHUD', 'RxCocoa', 'SnapKit', 'ZLPhotoBrowser']

post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| if need_otherlinkerflags_frameworks.include?(target.name) config.build_settings['OTHER_LDFLAGS'] = '-Wl,-weak-lswiftCoreGraphics' end
end end end ``Pod install`後,編譯運行,發現可以正常運行了。再驗證一下,非低版本手機上是否受到影響,沒有影響,完美。

如果説還有問題,那麼target 裏面Build Phases -> Link Binary With Librarires 裏面添加libswiftCoreGraphics.tbd 就可以解決問題

3.視頻橫豎屏切換

[UIDevice currentDevice] 使用setValue:forKey:的方式在iOS16上面已經不可用,繼而要使用 我遇到一個奇怪的現象就是,自己升級到16.0.3 版本後突然視頻的橫屏放大不能用了,然後就做了iOS 16 判斷用了新的方法就好了。但刪除APP 去重新下載舊的APP。屏幕放大轉旋依然好用。

```if (@available(iOS 16.0, )) {     UIWindowScene windowScene = (UIWindowScene )[[[UIApplication sharedApplication] connectedScenes] allObjects].firstObject;     UIWindowSceneGeometryPreferencesIOS perference = [[UIWindowSceneGeometryPreferencesIOS alloc] init];     perference.interfaceOrientations = 1 << deviceOrientation;     [windowScene requestGeometryUpdateWithPreferences:perference errorHandler:^(NSError * _Nonnull error) {         NSLog(@"error--%@", error);     }]; } else {         [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:deviceOrientation] forKey:@"orientation"];         [UIViewController attemptRotationToDeviceOrientation]; }

```

4.iOS normal arm64 com.apple.xcode.tools.swift.compiler is not absolute.

``` iOS normal arm64 com.apple.xcode.tools.swift.compiler is not absolute.

```

報錯顯示上面的問題,刪掉了User Header Search Paths中的內容,清理了緩存。

後續有發現新的問題再更新。

「其他文章」