您的运行环境禁止了 JavaScript 的执行,请开启后重新打开该页面! iOS16强制屏幕方向失效问题 - 鹏_bcf3 - 简书
精彩文章免费看

iOS16强制屏幕方向失效问题

1.背景:某一天发现unity开发的游戏在iOS16.2上会偶现出现竖屏的情况(supportedInterfaceOrientationsForWindow里已限制只能左右旋转)以下方法都不管用

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window;
if (@available(iOS 16.0, *)) {
    [vc.navigationController setNeedsUpdateOfSupportedInterfaceOrientations];
  
    NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
    UIWindowScene *ws = (UIWindowScene *)array[0];
    UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
    geometryPreferences.interfaceOrientations = UIInterfaceOrientationMaskLandscapeLeft;
    [ws requestGeometryUpdateWithPreferences:geometryPreferences
        errorHandler:^(NSError * _Nonnull error) {
        //业务代码
    }];
}

2.游戏引擎:Unity 2019
最后发现:游戏退出的时候调用UnityCleanup函数,il2cpp会清理一些子线程,由于c#子线程在wait,过5s清理不掉就会导致一个crash

image.png
最后编辑于:2023-02-25 21:35