检测版本更新

- (BOOL)checkHaveNewVersion_Func

{

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    __block BOOL bHaveNewVersionFlag = FALSE; // 有新版本标志

    

//    // 首先取得本地程序版本号

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

//这个地方 一定要注意,因为appstore里返回的版本信息最前面加了个V  所以这个地方必须也加个

    NSString *localVersion = [NSString stringWithFormat:@"V%@",[infoDic objectForKey:@"CFBundleShortVersionString"]];     

    

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        

        // 发送检测版本数据到app store

        NSString *URL = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", APPID];


        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

        [request setURL:[NSURL URLWithString:URL]];

        [request setHTTPMethod:@"POST"];

        

        NSHTTPURLResponse *urlResponse = nil;

        __block NSError *error = nil;

        NSData *recervedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];

        

        dispatch_async(dispatch_get_main_queue(), ^{

            //IOS5自带解析类NSJSONSerializationresponse中解析出数据放到字典中: json4种方式用法及比较http://blog.csdn.net/enuola/article/details/7903632

            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:recervedData options:NSJSONReadingMutableLeaves error:&error];

        

            // 解析数据

            NSArray *infoArray = [dic objectForKey:@"results"];

            if (0 < [infoArray count]) {

                NSDictionary *releaseInfo = [infoArray objectAtIndex:0];

                NSString *appStoreVersion = [releaseInfo objectForKey:@"version"];

                // appstore版本比本地版本高,则可更新

                

                if (NSOrderedAscending == [localVersion compare:appStoreVersion]) { // 有新版本

                    bHaveNewVersionFlag = YES;

                    

                    [MBProgressHUD hideHUDForView:self.view animated:YES];

                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:MY_Local_Str(@"温馨提示") message:MY_Local_Str(@"已有新版本,是否前去更新") delegate:self cancelButtonTitle:MY_Local_Str(@"暂不更新") otherButtonTitles:MY_Local_Str(@"更新"), nil];

                    [alertView show];

                    

                    

                } else { // 无新版本

                    

                    bHaveNewVersionFlag = NO;

                    [MBProgressHUD hideHUDForView:self.view animated:YES];

                    [GlobalClass promptWithString:@"当前程序已是最新版本" onView:self.view];

                    

                }

            } else {

                bHaveNewVersionFlag = NO;

                [MBProgressHUD hideHUDForView:self.view animated:YES];

                [GlobalClass promptWithString:@"当前程序已是最新版本" onView:self.view];

            }

        });

    });

    

    return bHaveNewVersionFlag;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值