zoukankan      html  css  js  c++  java
  • iOS 通过苹果开放API检测更新

    #define APPID @"1067207206"
    
    -(void)onCheckVersion
    {
        NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
        //CFShow((__bridge CFTypeRef)(infoDic));
        NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"];
    
        NSString *URL = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",APPID];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:[NSURL URLWithString:URL]];
        [request setHTTPMethod:@"POST"];
        NSHTTPURLResponse *urlResponse = nil;
        NSError *error = nil;
        NSData *recervedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
    
        NSString *results = [[NSString alloc] initWithBytes:[recervedData bytes] length:[recervedData length] encoding:NSUTF8StringEncoding];
        NSDictionary *dic = [results JSONValue];
        NSArray *infoArray = [dic objectForKey:@"results"];
        if ([infoArray count]) {
            NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
            NSString *lastVersion = [releaseInfo objectForKey:@"version"];
    
            if (![lastVersion isEqualToString:currentVersion]) {
                //trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil];
                alert.tag = 10000;
                [alert show];
            }
            else
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"此版本为最新版本" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                alert.tag = 10001;
                [alert show];
            }
        }
    }
    
  • 相关阅读:
    nodejs websocket
    [Java] 数组-01 入门
    [Java] 第一,二章 配置, 基础
    [Java] 第四章 异常机制
    [Java] 第三章 面向对象总结
    [Java] 接口-02
    [Java] 接口-01
    [Java] final 关键字
    [Java] 抽象类
    [Java] 多态-01
  • 原文地址:https://www.cnblogs.com/mapanguan/p/5507843.html
Copyright © 2011-2022 走看看