美文网首页
iOS检查更新

iOS检查更新

作者: 风雪山神喵 | 来源:发表于2018-06-21 10:14 被阅读0次

    //以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);

                                             }];

                                             [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) {

                                 }];

    相关文章

      网友评论

          本文标题:iOS检查更新

          本文链接:https://www.haomeiwen.com/subject/kxmojftx.html