iOS应用版本更新

#import "AppDelegate.h" 文件中的application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中调用检测结果

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //ios应用版本更新

    [self VersionClick];

    return YES;

}

获得发布版本的Version

//更新实现方法

-(void)VersionClick{

//获取发布版本的Version,id替换成自己应用的id

    NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://itunes.apple.com/lookup?id=662004496"] encoding:NSUTF8StringEncoding error:nil];

    if (string !=nil && [string length]>0 && [string rangeOfString:@"version"].length==7) {

        [self checkAppUpdata:string];

    }

}

比较当前版本与新上线版本做比较

#pragma mark ---比较当前版本与新上线版本做比较

-(void)checkAppUpdata:(NSString *)appInfo{

    //获取当前版本

    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

    NSString *appInfo1 = [appInfo substringFromIndex:[appInfo rangeOfString:@"\"version\":"].location + 10];

    appInfo1 = [[appInfo1 substringToIndex:[appInfo1 rangeOfString:@","].location] stringByReplacingOccurrencesOfString:@"\"" withString:@""];

    //判读,如果不同,则进入更新

    if (![appInfo1 isEqualToString:version]) {

        NSLog(@"新版本:%@,当前版本:%@",appInfo1,version);

        if ([[UIDevice currentDevice].systemVersion intValue] >= 9.0) {

            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:[NSString stringWithFormat:@"新版本 %@ 已发布!",appInfo1] preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

                

            }];

            UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"前往更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

                [self Updata];

            }];

            [alertController addAction:cancelAction];

            [alertController addAction:otherAction];

            

        }else

        {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"新版本 %@ 已发布!",appInfo1] delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:@"前往更新", nil];

            alert.delegate = self;

            [alert show];

        }

    }

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex ==1 ) {

        [self Updata];

    }

}

-(void)Updata{

    NSString *url = @"";//填写自己应用的更新地址

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值