版本号设置、检测与更新

1、版本检测代码:

-(void)checkVersion

{

    //当前版本号

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

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

    //AppStore发送同步请求

    NSString *URL = @"http://itunes.apple.com/lookup?id=752875885";//你的AppID

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

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

    [request setHTTPMethod:@"POST"];

    NSHTTPURLResponse *urlResponse = nil;

    NSError *error = nil;

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

    //收到返回结果

    NSDictionary *dic =   [[CJSONDeserializer deserializer] deserializeAsDictionary:recervedData error:&error] ;

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

    if ([infoArray count]) {

        NSDictionary *releaseInfo = [infoArray objectAtIndex:0];

//得到最新appstore上的版本号

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

//如果当前版本与appstore上的版本不一样

        if (![lastVersion isEqualToString:currentVersion]) {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本,是否前往更新?" delegate:self cancelButtonTitle:@"不更新" otherButtonTitles:@"更新", nil];

            alert.tag = 1000;

            [alert show];

        }

    }

}


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

{

    if (alertView.tag==10000) {

        if (buttonIndex==1) {

    //跳转到appstore的下载页

            NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/cn/app/yourappname/idxxxxxx?mt=8"];

            [[UIApplication sharedApplication]openURL:url];

        }

    }

}


2、如何设置当前工程app的版本号


(1)只要简单地设置version和build,其他地方(比如Info.plist)的版本号都会随之改变。可以简单地将version和build设置成一样的。

至于二者的差别可以参考此文:http://blog.csdn.net/kafeidev/article/details/8221273

(2)上面的代码 NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"];取出来的build的内容

3、如何知道app在App Store上的ID

(1)在App Store里搜索出你的app,然后右击“拷贝链接”,就可以得到app的下载地址:https://itunes.apple.com/cn/app/ju-duan/idxxxxxx?mt=8,id后面跟的内容就是你的appid。

(2)登录开发者账号,进入“manage your apps”也可找到对应的app的apple id



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值