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