版本号设置、检测与更新

来源:互联网 发布:天津稀有金属交易软件 编辑:程序博客网 时间:2024/05/17 08:30

1、版本检测代码:

-(void)checkVersion

{

    //当前版本号

    NSDictionary *infoDic = [[NSBundlemainBundle] infoDictionary];

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

    //AppStore发送同步请求

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

    NSMutableURLRequest *request = [[NSMutableURLRequestalloc] init];

    [requestsetURL:[NSURLURLWithString:URL]];

    [requestsetHTTPMethod:@"POST"];

   NSHTTPURLResponse *urlResponse = nil;

   NSError *error = nil;

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

    //收到返回结果

   NSDictionary *dic =   [[CJSONDeserializerdeserializer] deserializeAsDictionary:recervedDataerror:&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 = [[UIAlertViewalloc] initWithTitle:@"更新"message:@"有新的版本,是否前往更新?" delegate:self cancelButtonTitle:@"不更新"otherButtonTitles:@"更新",nil];

            alert.tag =1000;

            [alertshow];

        }

    }

}


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

{

   if (alertView.tag==10000) {

       if (buttonIndex==1) {

    //跳转到appstore的下载页

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

            [[UIApplicationsharedApplication]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
原创粉丝点击