.m
+ (UIViewController *)chooseRootViewController
{
UIViewController *rootVc = nil;
// 判斷下用戶有沒(méi)有最新的版本
// 最新的版本都是保存到info.plist
// 從info.plist文件獲取最新版本
// 獲取info.plist
NSString *infoPath = [[NSBundle mainBundle] pathForResource:@"Info.plist" ofType:nil];
// NSDictionary *dcit = [NSDictionary dictionaryWithContentsOfFile:infoPath];
NSDictionary *dict = [NSBundle mainBundle].infoDictionary;
// 獲取最新的版本號(hào)
NSString *curVersion = dict[@"CFBundleShortVersionString"];
// 獲取上一次的版本號(hào)
NSString *lastVersion = [XMGSaveTool objectForKey:XMGVersionKey];
// 之前的最新的版本號(hào) lastVersion
if ([curVersion isEqualToString:lastVersion]) {
// 版本號(hào)相等
rootVc = [[XMGTabBarController alloc] init];
}else{ // 有最新的版本號(hào)
// 保存最新的版本號(hào)
// 保存到偏好設(shè)置
[XMGSaveTool setObject:curVersion forKey:XMGVersionKey];
// 創(chuàng)建新特性界面
rootVc = [[XMGNewFeatureViewController alloc] init];
}
return rootVc;
}
.h
@interface XMGGuideTool : NSObject
// 選擇窗口根控制器
+ (UIViewController *)chooseRootViewController;
@end
AppDelegate
.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 1.創(chuàng)建窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// 2.設(shè)置窗口的根控制器
// 選擇根控制器
self.window.rootViewController = [XMGGuideTool chooseRootViewController];
// 3.顯示窗口
[self.window makeKeyAndVisible];
return YES;
}