ios 版本更新

来源:互联网 发布:视频传输软件 编辑:程序博客网 时间:2024/04/29 06:30

NSDictionary *infoDict = [[NSBundlemainBundle] infoDictionary];

    NSString *currentVersion = [infoDictobjectForKey:@"CFBundleVersion"];

    double doubleCurrentVersion = [currentVersiondoubleValue];

    

    NSURLRequest *req = [NSURLRequestrequestWithURL:[NSURLURLWithString:@"http://itunes.apple.com/lookup?id=你的appid"]];

    

    AFHTTPRequestOperation *request = [[AFHTTPRequestOperationalloc] initWithRequest:req];

    

    [request setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,id responseObject) {

        

        

        NSString *str=[[NSStringalloc] initWithData:responseObject encoding:NSUTF8StringEncoding];

        

        NSDictionary *jsonData =  [NSJSONSerializationJSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]options:NSJSONReadingMutableContainerserror:nil];

        

        NSLog(@"%@",jsonData);

        

        NSArray *infoArray = [jsonDataobjectForKey:@"results"];

        if (infoArray.count!=0) {

            NSDictionary *releaseInfo = [infoArrayobjectAtIndex:0];

            

            NSString *latestVersion = [releaseInfoobjectForKey:@"version"];

            

            NSString *trackViewUrl = [releaseInfoobjectForKey:@"trackViewUrl"];

            _updateUrl = trackViewUrl;

            

            double updateVersion = [latestVersiondoubleValue];

            

            if (updateVersion > doubleCurrentVersion) {

                

                UIAlertView *alertd = [[UIAlertViewalloc] initWithTitle:@"温馨提示"message:@"检测到有新版本,立即前往更新?"delegate:selfcancelButtonTitle:@"暂不更新"otherButtonTitles:@"立即前往",nil];

                alertd.tag =110;

                [alertd show];

            }else

            {

//                [[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前已是最新版本" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];

            }

        }else{

//            [[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前已是最新版本" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];

        }

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

//        [self errorActionWith:error];

    }];

    

    [request start];

}

0 0
原创粉丝点击