zoukankan      html  css  js  c++  java
  • 关于提示版本升级~

    今天遇到了关于版本升级的问题,弹出提示框给用户提醒升级,一个版本只提醒一次

    http://www.jianshu.com/p/62a18e8ed92b   这个是原文,但是有错误 这里改动了一下加了些需求

     

    #define kAPP_URL [AppDelegate isLanguageEnglish]?@"http://itunes.apple.com/lookup?id=":@"http://itunes.apple.com/cn/lookup?id="

    #define kAppId  @"1111111111"//appID

     

    - (void)updateApp

    {

        NSError *error;

        

        NSString *urlStr = [NSString stringWithFormat:@"%@%@",kAPP_URL,kAppId];

        NSURL *url = [NSURL URLWithString:urlStr];

        NSURLRequest *request = [NSURLRequest requestWithURL:url];

        NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

        

        NSDictionary *appInfoDict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:&error];

        

        if (error) {

            NSLog(@"%@", error.description);

            return;

        }

        

        NSArray *resultArray = [appInfoDict objectForKey:@"results"];

        

        if (![resultArray count]) {

            NSLog(@"error : resultArray == nil");

            return;

        }

        

        NSDictionary *infoDict = [resultArray objectAtIndex:0];

        //获取服务器上应用的最新版本号

        NSString *updateVersion = infoDict[@"version"];

        NSString *trackName = infoDict[@"trackName"];

        

        _trackViewUrl = infoDict[@"trackViewUrl"];

        

        //获取当前设备中应用的版本号

        NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];

        NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];

        

        NSArray<NSString*> *currentArray = [currentVersion componentsSeparatedByString:@"."];

        NSArray<NSString*> *updateArray = [updateVersion componentsSeparatedByString:@"."];

        

        NSMutableString *currentString = [NSMutableString string];

        for (NSString *str in currentArray) {

            NSString * tempstr = [NSString stringWithFormat:@"%03d",[str intValue]];

            [currentString appendString:tempstr];

        }

        

        NSMutableString *updateString = [NSMutableString string];

        for (NSString *str in updateArray) {

            NSString * tempstr = [NSString stringWithFormat:@"%03d",[str intValue]];//补全位数再比较大小

            [updateString appendString:tempstr];

        }

        if ([[NSUserDefaults standardUserDefaults]objectForKey:updateString]) {

            return;

        }else{

            [[NSUserDefaults standardUserDefaults]setObject:@0 forKey:updateString];//一个版本只提醒一次

        }

        

        //判断两个版本是否相同

        if ([currentString longLongValue] < [updateString longLongValue]) {

            NSString *titleStr = [NSString stringWithFormat:@"检查更新:%@", trackName];

            NSString *messageStr = [NSString stringWithFormat:@"发现新版本 %@ 是否更新 %@", updateVersion,infoDict[@"releaseNotes"]];//版本更新内容

            

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:titleStr message:messageStr delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"升级", nil];

            

            alert.tag = [kAppId intValue];

            [alert show];

        }

    }

    //判断用户点击了哪一个按钮

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

    {

        if (alertView.tag == [kAppId intValue]) {

            if (buttonIndex == 1) { //打开app store上应用的详情页面

                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.trackViewUrl]];

            }

        }

    }

  • 相关阅读:
    golang 简易聊天
    golang 自定义封包协议(转的)
    PHP 7 测试用例(转)
    android 百度地图开发
    Android studio 签名使用转
    百度ueditor 拖文件或world 里面复制粘贴图片到编辑中 上传到第三方问题
    Android控件属性大全(转)
    Android studio 一个项目中添加两个module遇到的bug
    win7 64位DCOM配置(关于导出excel 配置计算机组件服务)(转)
    Python学习--07迭代器、生成器
  • 原文地址:https://www.cnblogs.com/huoran1120/p/5859856.html
Copyright © 2011-2022 走看看