iOS检查版本更新,以及获取不到版本信息问题

来源:互联网 发布:投资 行业 知乎 编辑:程序博客网 时间:2024/05/29 08:10

-(void)versionURL{

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
//耗时的操作---获取某个应用在AppStore上的信息,更改id就行
//检测版本信息 一定要注意 首先查看自己的应用销售范围是 哪里? 如果是只有一个中国 请选择1方法,否则选择 方法 2
、、、、1. NSString *stringApp = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/lookup?id=。。"]
encoding:NSUTF8StringEncoding error:nil];
、、、、2.NSString *stringApp = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"https://itunes.apple.com/lookup?id=。。"]
encoding:NSUTF8StringEncoding error:nil];

if (stringApp!=nil || stringApp.length>0)
{

NSData *data = [stringApp dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
//获得上线版本号
NSString *version = [[[dic objectForKey:@"results"]firstObject]objectForKey:@"version"];
//获得当前版本
NSString *currentVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"];
int currentVersionnum = [[currentVersion stringByReplacingOccurrencesOfString:@"." withString:@""] intValue];
int lastVersionnum = [[version stringByReplacingOccurrencesOfString:@"." withString:@""] intValue];
dispatch_async(dispatch_get_main_queue(), ^{
//更新界面
if (lastVersionnum > currentVersionnum) {

//自定义的更新提示弹框
}else{
//已是最高版本
NSLog(@"已经是最高版本");
}
});
}
});
}

//点击跳转到appstore
-(void) nowNewBtnClick:(UIButton *)btn{
NSURL *url = [NSURL URLWithString:@"App在appstore的URL"];
[[UIApplication sharedApplication]openURL:url];
}