首页 > IOS中打开应用实现检查更新的功能

IOS中打开应用实现检查更新的功能



//检查更新页面



- (void)Renew{

    

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

    

    NSString *version = [infoDic valueForKey:@"CFBundleShortVersionString"];

    

    NSString *ipstr = [NSObject  deviceIPAdress];

    

    NSString *paramIp = ipstr;

    

    NSTimeInterval time = [[NSDate  date]timeIntervalSince1970];

    

    long i = time;

    

    NSString *paramTime = [NSString stringWithFormat:@"%ld",i];

    

    NSString *signstr = [NSString  stringWithFormat:@"%@%@%@%@",paramTime,paramIp,@"phone_ios",@"d556bd3337cd909b49eb5e33f46ad65c"];

    

    NSString *md5str =  [signstr MD5Hash];

    

    NSString *mdstr = [md5str   lowercaseString];

    

    NSString *sign = mdstr;

    

    NSString *key = @"phone_ios";

    

    NSDictionary *param = @{

                            @"type" : @2,

                            

                            @"version" : version

                            

                            };

    

    NSDictionary *dict = @{

                           

                           @"paramTime" : paramTime,

                           

                           @"paramIp" : paramIp,

                           

                           @"sign":sign,

                           

                           @"key" : key,

                           

                           @"param":param

                           

                           };

    

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    

    manager.requestSerializer = [AFJSONRequestSerializer serializer];

    

    manager.responseSerializer =  [AFJSONResponseSerializer  serializer];

    

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];

    

    [manager POST:RenewUrl parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {

        

        NSDictionary *resultDic = responseObject[@"result"];

        

        _upgradeUrl = resultDic[@"upgradeUrl"];

        

          _force = resultDic[@"isForce"];

        NSLog(@"_force--------%@",_force);

     

        NSLog(@"%@",resultDic);

        

        if ([resultDic[@"isForce"]compare:@0] !=NSOrderedSame) {

            

        UIAlertView *isForceView = [[UIAlertView alloc]initWithTitle:@"特别提示" message:@"发现新版本" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"下载", nil];

            

            

            [isForceView show];

            

        }else if ([resultDic[@"version"]compare:version] != NSOrderedSame) {

            

            UIAlertView *resultView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"发现新版本" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"下载", nil];

            

            [resultView show];

            

        }else{

            

            return ;

        }

        

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        

        UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"网络有问题" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

        

        [errorView show];

        

        NSLog(@"%@",error);

    }];

}

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

    

    if ([_force compare:@1 ]!=NSOrderedSame) {

        

        if (buttonIndex==1) {

            

            [self  startDownLoad];

            

//            [[UIApplication  sharedApplication]openURL:[NSURL URLWithString:_upgradeUrl]];

        }

        

        }else if ([_force  compare:@0] !=NSOrderedSame){

        

        if ( buttonIndex == 1) {

            

//            [[UIApplication  sharedApplication]openURL:[NSURL URLWithString:_upgradeUrl]];

            

            [self  startDownLoad];

            

        }else if (buttonIndex == 0){

            

            exit(0);

            

        }

    }

    

}



- (void) startDownLoad{



    NSURL *url = [NSURL URLWithString:_upgradeUrl];

    

//    NSLog(@"url-------%@",url);

    

    NSURLRequest *request = [NSURLRequest  requestWithURL:url];

    

    NSURLConnection *connect = [NSURLConnection  connectionWithRequest:request delegate:self];

    

    [connect  start];

}

转载于:https://www.cnblogs.com/er-dai-ma-nong/p/4876047.html

更多相关: