iOS16 Xcode14 対応

1. 横画面と縦画面の切り替え

[UIDevice currentDevice] setValue:forKey: を使用する方法は iOS16 では使用できなくなり、UIWindowScene で関数リクエストを使用します。

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];
}


复制代码

1.1. iOS16で画面回転通知ができない

UIViewController のviewWillTransitionToSize:withTransitionCoordinator:をオーバーライドし、この関数で UI を処理する必要があります。

1.2、iOS16でYYTextView使用後、画面を回転できない

UITextView を使用した後、関数 requestGeometryUpdateWithPreferences:geometryPreferences errorHandler: を呼び出します: 要求が無効であり、画面を回転できません

分析: すべてのconnectedScenesを出力します

YYTextViewを使用する前にimage.png

YYTextViewを使用した後image.png

問題は、現在の UIWindowScene に YYTextView によって追加された YYTextEffectWindow の追加レイヤーがあることですウィンドウのこのレイヤーを削除するだけです。

2. dealloc 時に Xcode14 UIViewController がクラッシュする

iOS16 でのデバッグ中のエラー

アプリケーションは、<%s> オブジェクトの object-c ランタイムの割り当て解除の開始を回避しました。

理由: IOS16 Apple は、システム コントロール カテゴリ (Categroy) で + (void)initialize メソッドをオーバーライドすることを許可していません。

3. xcode14 で印刷したパッケージを使用すると、iOS12.2 以下のシステムがクラッシュする

otool ツールを使用してバイナリ検出を表示する

image.png

二进制里面多了一个 /usr/lib/swift/libswiftCoreGraphics.dylib (compatibility version 1.0.0, current version 120.100.0)

解决方法:

Build Phases -> Link Binary With Librarires 里面添加libswiftCoreGraphics.tbd

おすすめ

転載: juejin.im/post/7146043986707218440