美文网首页
VersionDemo版本更新

VersionDemo版本更新

作者: 粒粒儿 | 来源:发表于2016-06-08 11:00 被阅读31次

之前项目里使用到了版本更新,所以在这里记录下:

//
//  ViewController.m
//  VersionDemo
//
//  Created by zhengll on 16/5/24.
//  Copyright © 2016年 TipTimes-1. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIAlertViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self verSionMethd];
}
-(void) verSionMethd{
    
    NSDictionary * infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString * currentVersion = [infoDic objectForKey:@"FBundleVersion"];
    
    NSString * URL = @"http://itunes.apple.com/cn/lookup?id=APPID";//如果是国内的版本需要加上/cn/
    //APPID  是在AppStore上面的appid
    NSMutableURLRequest * request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:URL]];
    [request setHTTPMethod:@"POST"];
    NSHTTPURLResponse * urlResponse = nil;
    NSError * error = nil;
    NSData * recerveData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
    NSString * results = [[NSString alloc] initWithBytes:[recerveData bytes] length:[recerveData length] encoding:NSUTF8StringEncoding];
    
    NSData * jsonData = [results dataUsingEncoding:NSUTF8StringEncoding];
    
//    NSError * err;
    
    NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
    NSArray * infoArray = [dic objectForKey:@"results"];
    if ([infoArray count]) {
        NSDictionary * releaseInfo = [infoArray objectAtIndex:0];
        NSString * lastVersion = [releaseInfo objectForKey:@"version"];
        float last = [lastVersion floatValue];
        float current = [currentVersion floatValue];
        
        if (![lastVersion isEqualToString:currentVersion] && (last > current)) {//在此添加一个判断条件,这样就可以保证,当当前版本低于AppStore版本时进行提示,同时也防止审核不通过,因为现在apple审核不建议添加自定义的版本更新提示
            
   
            NSLog(@"新版本%@,当前版本%@",lastVersion,currentVersion);
            UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"新版本%@已发布!",lastVersion] delegate:self cancelButtonTitle:@"知道了" otherButtonTitles: nil];
            alertView.delegate = self;
            [alertView addButtonWithTitle:@"前往更新"];
            [alertView show];
            alertView.tag = 20;
            
        }else{
            UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:nil message:@"已是最高版本" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
            [alertView show];
            
        }
    }
    
}
-(void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1&& alertView.tag == 20) {
        NSString * url = @"url";//url是app 在 AppStore上面的下载地址
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

相关文章

  • VersionDemo版本更新

    之前项目里使用到了版本更新,所以在这里记录下:

  • 版本更新

    【更新内容】测试更新 【更新内容】 【版本】0.9【版本】

  • 远程更新 - 草稿 - 草稿

    【版本】2.0【版本】 【链接】【链接】 【更新】更新啦!【更新】

  • npm 更新版本

    npm 更新到最新的版本或者更新到指定的版本 查看npm的当前版本 更新到最新版本: 更新到指定版本:

  • 上进远程更新

    【版本】1.1【版本】 【链接】【链接】 【更新】【更新】

  • 辞别新版远程更新

    【版本】2.0【版本】 【链接】【链接】 【更新】【更新】

  • 测试

    更新内容《新版本》更新内容 更新版本《3.0》更新版本 更新链接《https://www.lanzous》更新链接

  • WriteConcern

    版本信息 当前版本 v1.0 版本历史 版本 更新时间 更新人 更新内容 v1.0 2015/10/...

  • rjkgx

    更新版本【】更新版本 更新内容《》更新内容 更新链接〖〗更新链接

  • 版本更新

    一般安卓应用在设置选项都有版本更新的功能,方便用户及时更新到最新版本应用内更新分为以下几个步骤: 1、通过接口获取...

网友评论

      本文标题:VersionDemo版本更新

      本文链接:https://www.haomeiwen.com/subject/krkjdttx.html