ChenYilong / CYLTabBarController

[EN]It is an iOS UI module library for adding animation to iOS tabbar items and icons with Lottie, and adding a bigger center UITabBar Item. [CN]【中国特色 TabBar】一行代码实现 Lottie 动画TabBar,支持中间带+号的TabBar样式,自带红点角标,支持动态刷新。【iOS13 & Dark Mode & iPhone XS MAX supported】
MIT License
6.9k stars 1.45k forks source link

修复AppDelegate没有window属性崩溃问题 #578

Open ixueadev opened 2 years ago

ixueadev commented 2 years ago



My issue:

当使用最新Xcode创建的项目时,AppDelegate里面没有window属性,会导致崩溃。

What I have done:

解决方法是在getMainWindow方法中访问AppDelegate属性时,判断是否有该属性,如果有才访问:

static inline UIWindow *getMainWindow(){
    ...
    if ([UIApplication.sharedApplication.delegate respondsToSelector:@selector(window)]) {
        //兼容新版项目结构,也就是AppDelegate没有window的情况
        window = UIApplication.sharedApplication.delegate.window;
    }
    ...
    return window;
}