Closed 295060456 closed 3 years ago
@295060456 多谢指正 , 代码改为下面这几种,是否更为通用?
因为 SceneDelegate 是一个工程里自定义的类名, 可以获取更通用的:
static inline UIWindow *getMainWindow(){
UIWindow *window = nil;
window = UIApplication.sharedApplication.delegate.window;
if (!window) {
if (@available(iOS 13.0, *)) {
NSSet<UIScene *> *connectedScenes = UIApplication.sharedApplication.connectedScenes;
if (connectedScenes.count > 0 ) {
UIWindowScene *scene = (UIWindowScene *)connectedScenes.anyObject;
window = scene.windows.firstObject;
}
}
}
return window;
}
或者
static inline UIWindow *getMainWindow(){
UIWindow *window = nil;
window = UIApplication.sharedApplication.delegate.window;
if (!window) {
if (@available(iOS 13.0, *))
{
for (UIWindowScene* wScene in [UIApplication sharedApplication].connectedScenes)
{
if (wScene.activationState == UISceneActivationStateForegroundActive)
{
window = wScene.windows.firstObject;
break;
}
}
}
}
return window;
}
window = UIApplication.sharedApplication.delegate.window; 有时候是拿不到值的,会出问题。我刚好碰上。你直接拉我给你的地址,将会看到效果
ios 13以后 用 SceneDelegate 来管理
//建议往最高处定义,全局引用
同时将- (CYLTabBarController *)cyl_tabBarController 里面进行替换