判断引导页首次出现方式:

//选择根控制器
+(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]];
}
}

最新文章

  1. TestNG中的数据源DataProvider概述
  2. js:字符串(string)转json
  3. Android 多进程编程 15问15答!
  4. File already exists: filesystem &#39;/path/file&#39;, transaction svn常见错误解决方法
  5. SVN解锁失败的解决办法
  6. 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”的解决方法!
  7. Java 解压zip压缩包
  8. PAT 1003. Emergency 单源最短路
  9. BST讲解
  10. java中的异常类
  11. Android : Resource is not a Drawable (color or path)
  12. Java字符串与数组
  13. material mem
  14. 网络I/O模型--03非阻塞模式(ServerSocket与Socket的超时处理)--解除accept()、 read()方法阻塞
  15. ZOJ 2319 Beautiful People
  16. hdu2993 MAX Average Problem (斜率dp)
  17. NFC学习总结
  18. 2018.11.19 Struts2中Action类的书写方式
  19. vue笔记v-bind
  20. linux知识目录

热门文章

  1. 当参数为带参数的url时怎么办?
  2. [实战]MVC5+EF6+MySql企业网盘实战(18)——文件上传,下载,修改
  3. MQTT协议以及库函数说明
  4. spring_150908_hibernate_id_sequence
  5. Jenkins配置agent
  6. 如何在 JavaScript 中检查字符串是否包含子字符串?
  7. 《java虚拟机》----java内存模型与线程
  8. keil中的memory model
  9. Juqery error () 出现 parsererror 问题
  10. python开发_python代码风格(coding style)