CYLTabBarController icon indicating copy to clipboard operation
CYLTabBarController copied to clipboard

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

Open ixueadev opened this issue 3 years ago • 0 comments



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

ixueadev avatar Dec 01 '21 05:12 ixueadev