ios App store版本更新

1.对于在app store上面的版本更新

//

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

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

    NSLog(@"currentVersion = %@",currentVersion); //本地的版本号


    NSString *url = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",kAPPID];//获取app store版本号

    [ZHSyncHttpNetworkRequest request:url postDataArray:nil completeBlock:^(NSData *data) { //数据获取(自己定义的类)加解析

        NSString *results = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

        id dict = [results JSONValue];

        NSArray *resultArray = [dict valueForKeyPath:@"results"];

        if ([resultArray count] > 0) {

            NSDictionary *contentDic = [resultArray objectAtIndex:0];

            NSString *lastVersion = [contentDic valueForKeyPath:@"version"];

            

            //NSString *trackUrl = [contentDic valueForKeyPath:@"trackViewUrl"];

            if (![currentVersion isEqualToString:lastVersion]) {//版本不同  两版本号对比

                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"发现新版本,是否现在更新" delegate:self cancelButtonTitle:nil otherButtonTitles:@"马上更新",@"稍后再说", nil];

                alertView.tag = 1001;

                [alertView show];

            }else{

                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前版本是最新版本" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];

                alertView.tag = 1002;

                [alertView show];

            }

        }

    } errorBlock:^(NSError *error) {

        NSLog(@"request failed in 版本更新");

    }];

#pragma mark UIAlertView delegate ---代理方法

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

{

    if (alertView.tag ==1001) {

        if (buttonIndex == 0) {

            [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:[NSStringstringWithFormat:@"https://itunes.apple.com/app/id%@",kAPPID]]];//前往更新

        }

    }

}


2.当然我们一般用的是此种来自 app store上的app下载,但是为了能方便统计来自多种渠道的版本更新我们一般采用umeng统计来进行检测版本更新。

(1)首先导入sdk :libMobClickLibrary.a和MobClick.h

(2)导入framework:libz.1.2.5.dylib

(3)在ZHAppDelegate.m中  #import "MobClick.h"然后在

application: didFinishLaunchingWithOptions:方法中将

[MobClickstartWithAppkey:@"umengKey"]; //umengKey是自己在官网申请的

[MobClick checkUpdate];  //通过查看文档可以查看mobClick类里面给我们封装好了很多的方法

版本更新检查




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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值