判断引导页首次出现方式:
//选择根控制器
+(void)chooseRootViewController{ //初始化Window窗口
[AppDelegate Delegate].window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
[AppDelegate Delegate].window.backgroundColor = [UIColor whiteColor];
[[AppDelegate Delegate].window makeKeyAndVisible]; //取出沙盒中存储的上次使用软件的版本号
NSString *key = @"CFBundleVersion";
NSString *lastVersion = [defaluts stringForKey:key]; //获取当前软件的版本号
NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];
if ([currentVersion isEqualToString:lastVersion]) {
if ([ToolManager maitchWithAccountNumAndPassword] && [ToolManager IsOrNoAutoLogin]== YES) {
//登录成功,进入主控制器
[AppDelegate Delegate].window.rootViewController = [[KJTabViewController alloc]init];
}else{
//用户已经注册过,进入登陆控制器
[self setLoginVC];
}
}else{ //用户初次使用,进入引导页控制器
[AppDelegate Delegate].window.rootViewController = [[KJGuidePageController alloc]init]; //存储新的版本号
[defaluts setObject:currentVersion forKey:key];
[defaluts synchronize];
}
}
版本更新方式:http://www.cnblogs.com/jys509/p/5390505.html
1.获取当前项目APP版本号
2.拿到AppStore项目版本号
3.对比版本号,实现更新功能
第一种方式:
/**
* 检测app更新
*/
-(void)hsUpdateApp
{
//1.先获取当前工程项目版本号
NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];
NSString *currentVersion=infoDic[@"CFBundleShortVersionString"]; //2.从网络获取appStore版本号
NSError *error;
NSData *response = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",STOREAPPID]]] returningResponse:nil error:nil];
if (response == nil) {
NSLog(@"你没有连接网络哦");
return;
}
NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
if (error) {
NSLog(@"hsUpdateAppError:%@",error);
return;
}
NSArray *array = appInfoDic[@"results"];
NSDictionary *dic = array[];
NSString *appStoreVersion = dic[@"version"];
//3.打印版本号
NSLog(@"当前版本号:%@\n商店版本号:%@",currentVersion,appStoreVersion);
//4当前版本号小于商店版本号,就更新
if([currentVersion floatValue] < [appStoreVersion floatValue])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本有更新" message:[NSString stringWithFormat:@"检测到新版本(%@),是否更新?",appStoreVersion] delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
[alert show];
}else{
NSLog(@"版本号好像比商店大噢!检测到不需要更新");
}
} - (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//5.实现跳转到应用商店进行更新
if(buttonIndex==)
{
//6.此处加入应用在app store的地址,方便用户去更新,一种实现方式如下:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", STOREAPPID]];
[[UIApplication sharedApplication] openURL:url];
}
}
第二种方式:
#pragma mark - 版本判断
/**
* 专用检测app更新
*/
-(void)judgeVersionUpdate
{
NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",STOREAPPID];
NSURL *url = [NSURL URLWithString:urlStr];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[NSURLConnection connectionWithRequest:req delegate:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSError *error;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSDictionary *appInfo = (NSDictionary *)jsonObject;
NSArray *infoContent = [appInfo objectForKey:@"results"];
NSString *appStoreVersion = [[infoContent objectAtIndex:] objectForKey:@"version"];
KJLog(@"商店的版本是:%@",appStoreVersion); NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
KJLog(@"当前的版本是:%@",currentVersion);
if (![appStoreVersion isEqualToString:currentVersion]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本有更新" message:[NSString stringWithFormat:@"检测到新版本(%@),是否更新?",appStoreVersion] delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
[alert show];
}
}
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==)
{
//此处加入应用在app store的地址,方便用户去更新
NSString *iTunesLink = [NSString stringWithFormat:@"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=%@&mt=8",STOREAPPID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
}
}