iOS开发,版本更新

新的iOS版本更新逻辑和旧的没有太大的区别,只是多了一个build和version的区别。

1.关于Version和Build

Version说白了就是版本号,也是提交到itunes的版本号,也就是请求http://itunes.apple.com/lookup?id=xxx返回的版本号

Build呢是用于在APP被拒之后递增一个版本时所用,截个图,说明问题:

1.1 比如我在submit之前在Xcode中设置的:


1.2 那么你submit之后在https://itunesconnect.apple.com看到的将是:


这样说,大家明白吧?

2.版本更新变化

由于Version和Build的区别,所以原来获取当前APP版本的方法:

[[[NSBundlemainBundle]infoDictionary]objectForKey:@"CFBundleVersion"]

获取到的将是Build的版本号

所以正确的方法是:

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

3.附带完整的版本更新方法如下

3.1 检查更新

[KVParserClient checkNewVersion:^(BOOL flag, NSError *error) {
        [SVProgressHUD dismiss];
        if (error) {
            [SVProgressHUD showErrorWithStatus:[error localizedDescription]];
        }else if (flag == false) {
            //[SVProgressHUD showSuccessWithStatus:@"已是最新版本"];
        }else if (flag == true) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self UPdateNewVersion];
            });
        }
    }];

- (void)UPdateNewVersion
{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"发现新版本" message:@"是否前往App Store更新?" delegate:self cancelButtonTitle:@"稍候" otherButtonTitles:@"确认", nil];
    [alertView show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex==0) {
        
    }else if (buttonIndex==1) {
        NSString *iTunesLink = [NSString stringWithFormat:@"http://itunes.apple.com/cn/app/id%@?mt=8",ITUNESAPPID];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
    }
}

3.2 具体更新请求方法

#define ITUNESAPPID @"xxxx"

typedef void (^CheckNewVersionHandler)(BOOL flag, NSError *error);

/*
 *判断是否是最新版
 */

+(void)checkNewVersion:(CheckNewVersionHandler )checkBlock
{
    
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",ITUNESAPPID]];
    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        
        if (!connectionError) {
            
            
            NSString *version = @"";
            NSDictionary *loginAuthenticationResponse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves|NSJSONReadingAllowFragments error:nil];
            NSArray *configData = [loginAuthenticationResponse valueForKey:@"results"];
            
            if (configData&&[configData count]>0) {
                for (id config in configData)
                {
                    version = [config valueForKey:@"version"];
                }
                if ([version floatValue] > [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]floatValue])
                {
                    checkBlock(true,nil);
                }
            }
        }
        checkBlock(false,connectionError);
    }];
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值