zoukankan      html  css  js  c++  java
  • oc自动检测更新app

    1.一定要先配置自己项目在商店的APPID,配置完最好在真机上运行才能看到完全效果

    2.获取当前工程项目版本号

    3.从网络获取appStore版本号

    4.当前版本号小于商店版本号,就更新

    代码如下:

    //商店的APPID

    #define STOREAPPID@"1080182980"

    -(void)UpdateApp

    {

        //2先获取当前工程项目版本号

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

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

        //3从网络获取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"];

        

        //打印版本号

        NSLog(@"当前版本号:%@ 商店版本号:%@",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(@"版本号好像比商店大噢!检测到不需要更新");

        }

    }

  • 相关阅读:
    Mybatis学习笔记(八) —— Mybatis整合spring
    Mybatis学习笔记(七) —— 关联查询
    Mybatis学习笔记(六) —— 动态sql
    Mybatis学习笔记(五) —— Mapper.xml(输入映射和输出映射)
    Mybatis学习笔记(四) —— SqlMapConfig.xml配置文件
    Mybatis学习笔记(三) —— DAO开发方法
    Mybatis学习笔记(二) —— mybatis入门程序
    Mybatis学习笔记(一) —— mybatis介绍
    tomcat的热部署配置
    int bool 字符串 列表 字典 集合
  • 原文地址:https://www.cnblogs.com/Yun-Longcom/p/11697317.html
Copyright © 2011-2022 走看看