iOS:判断引导页首次出现、版本更新

简介:

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

复制代码
//选择根控制器
+(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[0];
    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==1)
    {
        //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:0] 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==1)
    {
        //此处加入应用在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]];
    }
}
复制代码

 

程序猿神奇的手,每时每刻,这双手都在改变着世界的交互方式!
本文转自当天真遇到现实博客园博客,原文链接:http://www.cnblogs.com/XYQ-208910/p/5611107.html ,如需转载请自行联系原作者
相关文章
|
4月前
|
移动开发 开发工具 数据安全/隐私保护
iOS APP 版本更新升级教程:如何打包上架新的 APP 版本?
iOS APP 版本更新升级教程:如何打包上架新的 APP 版本?
iOS APP 版本更新升级教程:如何打包上架新的 APP 版本?
|
移动开发 开发工具 数据安全/隐私保护
iOS APP版本更新升级教程:如何打包上架新的APP版本?
本篇博客将介绍如何快速、简便地完成APP更新升级流程,让你的用户享受到更好的使用体验。使用常用开发工具打包,注意版本号的修改。进入APP页面点击“所有构建版本”选项,这里会显示上传成功的构建版本。输入更新说明,修改APP描述、关键词等,选择是否为新功能。如审核通过则恭喜你,否则根据反馈修改再重新上传提交审核。
|
JavaScript 前端开发 Android开发
根据js来判断手机是操作系安卓还是ios
根据js来判断手机是操作系安卓还是ios
568 0
|
iOS开发
iOS开发 - 渐变导航条升级版(判断滚动的方向和改变方向时的位置)
iOS开发 - 渐变导航条升级版(判断滚动的方向和改变方向时的位置)
130 0
iOS开发 - 渐变导航条升级版(判断滚动的方向和改变方向时的位置)
|
iOS开发
iOS开发 - touchBegan事件判断点击的位置在View上还是在View的子View上
iOS开发 - touchBegan事件判断点击的位置在View上还是在View的子View上
265 0
iOS开发 - touchBegan事件判断点击的位置在View上还是在View的子View上
|
iOS开发
iOS首次启动程序引导图
iOS首次启动程序引导图
203 0
iOS首次启动程序引导图
|
iOS开发
iOS开发 - ScrollView滚动时怎么判断滚动停止及滚动的方向
iOS开发 - ScrollView滚动时怎么判断滚动停止及滚动的方向
875 0
|
数据安全/隐私保护 iOS开发
iOS逆向小技能:解锁无密码的设备、判断设备是否锁定、锁定设备、打开某个程序
介绍lua 函数: runApp、closeApp、getScreenSize、getDeviceID、lua_exit、isFrontApp。
236 0
|
iOS开发
IOS版本更新代码——商店版本
IOS版本更新代码——商店版本
147 0
|
iOS开发
IOS常用正则表达式判断
IOS常用正则表达式判断
86 0