1 在app开发中,新特性界面的展现时间分为两个时间点:app
1) 程序第一次运行时(包括第一次安装后运行,卸载再安装后第一次运行);ide
2 )当程序发布新的版本时ui
处理这个逻辑关系代码通常写在AppDelegate.m中的app启动完成的方法- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中。spa
常见代码逻辑以下:开发
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {get
//建立windowit
self.window = [[UIWindow alloc] initWithFrame:kScreenSize];io
//设置window的根控制器object
self.window.rootViewController = [self pickViewController];select
//使window可见
[self.window makeKeyAndVisible];
//保存当前版本到沙盒中
[self saveAppVersion];
return YES;
}
#pragma mark 加载新特性页面和主页面的逻辑判断
//得到当前版本号
- (NSString *)loadCurrentAppVersion{
NSDictionary *infoDict = [NSBundle mainBundle].infoDictionary;
return infoDict[@"CFBundleShortVersionString"];
}
//将当前版本号保存到沙盒中
- (void)saveAppVersion{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
NSDictionary *infoDict = [NSBundle mainBundle].infoDictionary;
[ud setObject:infoDict[@"CFBundleShortVersionString"] forKey:@"appVersion"];
}
//取出沙盒中的版本号
- (NSString *)loadSavedAppVersion{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
return [ud objectForKey:@"appVersion"];
}
//根据版本号来判断是否加载新特性界面,只有第一次加载或则版本号变化时才加载新特性界面
- (UIViewController *)pickViewController{
if ([[self loadSavedAppVersion] isEqualToString:[self loadCurrentAppVersion]]) {
//跳转到主界面
return [[MYTabBarController alloc] init];
}else{
//跳转到新特性界面
return [[MYGuideController alloc] init];
}
}
2 通常在新特性界面的最后一页,在展现完最后一页新特性页面时,都会跳转到主页面,通常有两种方式跳转到主页面,一种是展现完新特性页面后直接填转到主页面;还有一种是在最后一页新特性页面中,建立一个体验按钮,经过点击体验按钮而跳转到主页面中。绝大多数都是第二种经过一个体验按钮而进入主页面,这种方式的常见处理方式是在建立的button中,添加一个target方法,经过这个方法来跳转到主页面,代码以下:
[enterBtn addTarget:self action:@selector(enter) forControlEvents:UIControlEventTouchUpInside];
- (void)enter{
MYTabBarController *tabBarController = [[MYTabBarController alloc] init];
//切换app的根控制器
[UIApplication sharedApplication].keyWindow.rootViewController = tabBarController;
}