- 首页 > it技术 > >
//以get的形式提交,get的参数就是上面的域名,parameters的参数是一个字典类型,将上面的字典作为它的参数
[[AFHTTPClient sharedClient] GET:[NSString stringWithFormat:@"%@%@",
@"http://itunes.apple.com/lookup?bundleId=",
@"com.pkuhit.syt"]parameters:nilprogress:nil
success:^(NSURLSessionDataTask*_Nonnulltask,id_NullableresultDic) {
// 隐藏系统风火轮
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSDictionary*infoDic=[[NSBundlemainBundle]infoDictionary];
NSString*serverVersion = [[[resultDicobjectForKey:@"results"]objectAtIndex:0]valueForKey:@"version"];
NSString*localVersion = infoDic[@"CFBundleShortVersionString"];
NSString*serverVersionName = serverVersion;
//是新版
if([serverVersioncompare:localVersion]>0){
NSRangerangeServer = [serverVersionrangeOfString:@"."];
NSRangerangeLocal = [localVersionrangeOfString:@"."];
NSMutableArray*serverList = [[NSMutableArrayalloc]init];
NSMutableArray*localList = [[NSMutableArrayalloc]init];
while(rangeServer.length>0) {
[serverListaddObject: [serverVersionsubstringToIndex:NSMaxRange(rangeServer)-1]];
serverVersion = [serverVersionsubstringFromIndex:NSMaxRange(rangeServer)];
rangeServer = [serverVersionrangeOfString:@"."];
}
[serverListaddObject:serverVersion];
while(rangeLocal.length>0) {
[localListaddObject: [localVersionsubstringToIndex:NSMaxRange(rangeLocal)-1]];
localVersion = [localVersionsubstringFromIndex:NSMaxRange(rangeLocal)];
rangeLocal = [localVersionrangeOfString:@"."];
}
[localListaddObject:localVersion];
if([serverList[0]compare:localList[0]]>0){
NSString*alertMsg=[[@"省医通"stringByAppendingString:[NSStringstringWithFormat:@"%@",serverVersionName]]stringByAppendingString:@",请先更新再使用!"];
NSString*str = [[[resultDicobjectForKey:@"results"]objectAtIndex:0]valueForKey:@"trackViewUrl"];
NetworkAlertView *alertView = [[NetworkAlertView alloc]initWithTitleNoCancel:alertMsg withCancelBlock:nil withSettingBlock:^ {
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:str]];
exit(0);
}];
【iOS检查更新】[alertViewshow];
}elseif([serverList[1]compare:localList[1]]>0){
NSString*alertMsg=[[@"省医通"stringByAppendingString:[NSStringstringWithFormat:@"%@",serverVersionName]]stringByAppendingString:@",请先更新再使用!"];
NSString*str = [[[resultDicobjectForKey:@"results"]objectAtIndex:0]valueForKey:@"trackViewUrl"];
NetworkAlertView *alertView = [[NetworkAlertView alloc]initWithTitleNoCancel:alertMsg withCancelBlock:nil withSettingBlock:^ {
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:str]];
exit(0);
}];
[alertViewshow];
}elseif([serverList[2]compare:localList[2]]>0){
NSString*alertMsg=[[@"省医通"stringByAppendingString:[NSStringstringWithFormat:@"%@",serverVersionName]]stringByAppendingString:@",请先更新再使用!"];
NSString*str = [[[resultDicobjectForKey:@"results"]objectAtIndex:0]valueForKey:@"trackViewUrl"];
NetworkAlertView *alertView = [[NetworkAlertView alloc]initWithTitle:alertMsg withCancelBlock:nil withSettingBlock:^ {
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:str]];
}];
[alertViewshow];
}
}
}failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {
}];
推荐阅读