您的位置:首页 > 移动开发 > IOS开发

ios 版本更新

2015-08-03 16:26 465 查看
NSDictionary *infoDict = [[NSBundle
mainBundle] infoDictionary];
    NSString *currentVersion = [infoDict
objectForKey:@"CFBundleVersion"];
    double doubleCurrentVersion = [currentVersion
doubleValue];
    
    NSURLRequest *req = [NSURLRequest
requestWithURL:[NSURL
URLWithString:@"http://itunes.apple.com/lookup?id=你的appid"]];
    
    AFHTTPRequestOperation *request = [[AFHTTPRequestOperation
alloc] initWithRequest:req];
    
    [request setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,
id responseObject) {
        
        
        NSString *str=[[NSString
alloc] initWithData:responseObject 
encoding:NSUTF8StringEncoding];
        
        NSDictionary *jsonData =  [NSJSONSerialization
JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]
options:NSJSONReadingMutableContainers
error:nil];
        
        NSLog(@"%@",jsonData);
        
        NSArray *infoArray = [jsonData
objectForKey:@"results"];
        if (infoArray.count!=0) {
            NSDictionary *releaseInfo = [infoArray
objectAtIndex:0];
            
            NSString *latestVersion = [releaseInfo
objectForKey:@"version"];
            
            NSString *trackViewUrl = [releaseInfo
objectForKey:@"trackViewUrl"];
            _updateUrl = trackViewUrl;
            
            double updateVersion = [latestVersion
doubleValue];
            
            if (updateVersion > doubleCurrentVersion) {
                
                UIAlertView *alertd = [[UIAlertView
alloc] initWithTitle:@"温馨提示"
message:@"检测到有新版本,立即前往更新?"
delegate:self
cancelButtonTitle:@"暂不更新"
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];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息