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];
            }
        }
    }
    
  • 相关阅读:
    大数据测试2
    大数据测试3
    CROSS APPLY和 OUTER APPLY 区别详解
    SQL中的escape的用法
    Sql Server参数化查询之where in和like实现详解
    多行文本框换行符处理
    Cross Apply的用法
    交叉连接Cross Join的用法
    统计字符串中某个字符的个数
    JOIN用法
  • 原文地址:https://www.cnblogs.com/mapanguan/p/5507843.html
Copyright © 2011-2022 走看看