项目描述:在程序启动的时候要检查程序的版本升级,就是在的AppDelegate里有一个FUNC区检查版本升级。去强制或者选择升级,并且必须还要获取一个时间戳,这个时间戳并且还在登录的时候用到这个时间戳。
那么问题就来了:在第一次启动的时候打开就是登录页面,当我们点击登录的时候,极有可能在触发登录事件时,这个获取时间戳还没有获取到。
解决问题办法:在我登录页面上的当前的Window上添加了一个图,并且在这个图上添加了一个和当前视图一样大得的UIImageView,这个上面的图片就是我们设置的启动图了。
当在AppDelegate的网络的请求成功下来的时候,在发出一个通知。登录页面接受广播,在把当前窗口上得查看父从视图removeFromSuperview掉。
再顺便解释一下网络上得设置办法
[NSThread sleepForTimeInterval:2.0];
这个方法的英文可以控制启动页的停留时间,控制的英文当前主线程的停止,你可以试着用个异步线程去试一下,根本没用!TMD。想要单独的暂停启动页这个方法的英文可以的。
上代码:
AppDelegate的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:[[MainViewController alloc]init]];
self.window.rootViewController = nvc;
[self updateVersion];
[self.window makeKeyAndVisible];
return YES;
}
// 检查版版本更新
-(void)updateVersion {
NSUserDefaults * userDefault = [NSUserDefaults standardUserDefaults];
[userDefault setValue:@"洲洲哥" forKey:USERID];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"-----------------AppDelegate----------------AppDelegate----------------");
NSDictionary *dict = @{@"KEYS":@"WANGHUIZHOU"};
// 发送接收成功的通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"installType" object:nil userInfo:dict];
});
}
// 检查版版本更新
-(void)updateVersion {
NSUserDefaults * userDefault = [NSUserDefaults standardUserDefaults];
[userDefault setValue:@"洲洲哥" forKey:USERID];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"-----------------AppDelegate----------------AppDelegate----------------");
NSDictionary *dict = @{@"KEYS":@"WANGHUIZHOU"};
// 发送接收成功的通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"installType" object:nil userInfo:dict];
});
}
loginViewCOntroller代码
// 宏定义得到当前的Window
#define CurrentWindow [self getCurrentWindowView]
- (instancetype)init
{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(installProcess:) name:@"installType" object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"标题";
self.launchView = [[UIView alloc] initWithFrame:self.view.bounds];
UIImageView * backImageView = [[UIImageView alloc] initWithFrame:self.launchView.bounds];
backImageView.image = [UIImage imageNamed:@"launch"];
[self.launchView addSubview:backImageView];
self.launchView.backgroundColor = [UIColor redColor];
[CurrentWindow addSubview:self.launchView];
}
-(void)installProcess:(NSNotification *)notification {
[UIView animateWithDuration:0.25 animations:^{
[self.launchView removeFromSuperview];
NSLog(@"-----END----%@",USERID);
}];
}
/**获取当前window*/
- (UIWindow *)getCurrentWindowView {
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
if (window.windowLevel != UIWindowLevelNormal)
{
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow * tmpWin in windows)
{
if (tmpWin.windowLevel == UIWindowLevelNormal)
{
window = tmpWin;
break;
}
}
}
return window;
}
网友评论