这种有时候不行:
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
下面这些任何情况都可以:
UIWindow *window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UIWindow *window =[[UIApplication sharedApplication].delegate window];
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
UIWindow *window = [UIApplication sharedApplication].windows[0];