1 //获取当前window 2 + (UIWindow *)mainWindow 3 { 4 UIApplication *app = [UIApplication sharedApplication]; 5 if ([app.delegate respondsToSelector:@selector(window)]) 6 { 7 return [app.delegate window]; 8 } 9 else 10 { 11 return [app keyWindow]; 12 } 13 }