iOS 内置更新

最近客户要求做一个APP内部更新的需求,,第一次我是不知道有iOS 内置更新的机制,所以我就和后台协商,通过后台返回的版本号来控制版本更新,这样做的话,基本的功能是完成了,但是这样有点麻烦,而且更新不是很及时,需要后台操作,于是我听到别人说有iOS 有内置的更新机制,就有了以下。。。。
  • iOS 版本更新,在app内部千万别暴露一些“版本更新字眼”或者是“版本更新的按钮”,否则一经发现,审核时通过不了的
  • iOS 内置的更新是通过获取已经上架到App Store的app的版本号和当前app的版本号进行比较

来看以下代码

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px 'PingFang SC'; color: #1d9421}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #1d9421}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #6122ae}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; min-height: 20.0px}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #1337ff}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #c91b13}p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #3d1d81}p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #294c50}span.s1 {font: 17.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #000000}span.s2 {font: 17.0px Menlo; font-variant-ligatures: no-common-ligatures}span.s3 {font-variant-ligatures: no-common-ligatures}span.s4 {font-variant-ligatures: no-common-ligatures; color: #1d9421}span.s5 {font: 17.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures}span.s6 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s7 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s8 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s9 {font-variant-ligatures: no-common-ligatures; color: #6122ae}span.s10 {font-variant-ligatures: no-common-ligatures; color: #c91b13}span.s11 {font-variant-ligatures: no-common-ligatures; color: #1337ff}span.s12 {font-variant-ligatures: no-common-ligatures; color: #c32275}span.s13 {font-variant-ligatures: no-common-ligatures; color: #78492a}span.s14 {font: 17.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #1d9421}span.s15 {font: 17.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #c91b13}span.s16 {font-variant-ligatures: no-common-ligatures; color: #294c50}

 //先拿到当前的app版本号
    /*
     这是版本号,展示在app内部的和App Store
     CFBundleShortVersionString
    1.0.2
     这是构建版本
     CFBundleVersion
     7
     */
    NSDictionary *info = [NSBundle mainBundle].infoDictionary;
    NSString *currentVersion = info[@"CFBundleShortVersionString"];
    
    /*
     https://itunes.apple.com/lookup?id=1209893430
     下面这个链接就是获取app 在App Store上的信息
     id=1209892438 只要把这个appid换成你要的就好
     */
    NSString *urlAppstore = [NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=1209892438"];
    NSURL *url = [NSURL URLWithString:urlAppstore];
    //发送请求
    NSString *requestUrl = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    //进行解析
    NSError *error = nil;
    NSData *jsonData = [requestUrl dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *appInfo = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:&error];
    if (!error && appInfo) {
        ZLFLog(@"%@",appInfo);
        NSArray *appArr = appInfo[@"results"];
        NSDictionary *appInfo2 = appArr.firstObject;
        NSString *appStroeVersion = appInfo2[@"version"];
        NSString *urlUpData = appInfo2[@"trackViewUrl"];
        if ([currentVersion compare:appStroeVersion options:NSNumericSearch] == NSOrderedAscending) {// 升序 发现新版本
            [self alertViewControllertitle:@"发现新版本,是否更新到最新版本?" message:@"" confirm:^(id confir) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlUpData]];
            } don:^(id don) {
                
            }];
            
        }else{
            ZLFLog(@"没有新的版本");
        }
    }

这样就能实现自动更新了

你可能感兴趣的:(iOS 内置更新)