zoukankan      html  css  js  c++  java
  • 【源码】iOS-App版本更新提示

    //检查版本更新

    -(void)VersionRequestApi

    {

        //异步线程//处理耗时操作的代码块

        dispatch_async(dispatch_get_global_queue(0, 0), ^{

            //App内info.plist文件里面版本号

            NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];

            CurrentVersion = infoDict[@"CFBundleShortVersionString"];//本地的版本号

            // 取得AppStore信息

            MyURL = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@", @"1336413759"];

            [[ApiTool shareApiTool] post:MyURL params:nil success:^(NSDictionary *jsonDic) {

                NSArray *results = [jsonDic objectForKey:@"results"];

                AppStoreVersion = [results[0] objectForKey:@"version"];//appstore的版本号

                ReleaseNotes = [results[0] objectForKey:@"releaseNotes"];//更新描述

                trackViewUrl = [results[0] objectForKey:@"trackViewUrl"];//跳转AppStore需要的url

                NSLog(@"AppStoreVersion:%@,ReleaseNotes:%@,trackViewUrl:%@",AppStoreVersion,ReleaseNotes,trackViewUrl);

                //比较版本号

                NSArray *curVerArr = [CurrentVersion componentsSeparatedByString:@"."];

                NSArray *appstoreVerArr = [AppStoreVersion componentsSeparatedByString:@"."];

                BOOL needUpdate = NO;//是否需要更新

                //比较版本号大小

                int maxv = (int)MAX (curVerArr.count, appstoreVerArr.count);

                int cver = 0;

                int aver = 0;

                for (int i = 0; i < maxv; i++)

                {

                    if (appstoreVerArr.count > i)

                    {

                        aver = [NSString stringWithFormat:@"%@", appstoreVerArr[i]].intValue;

                    }

                    else

                    {

                        aver = 0;

                    }

                    if (curVerArr.count > i)

                    {

                        cver = [NSString stringWithFormat:@"%@", curVerArr[i]].intValue;

                    }

                    else

                    {

                        cver = 0;

                    }

                    

                    if (aver == cver)

                    {

                        continue;

                    }

                    else if (aver > cver)

                    {

                        needUpdate = YES;

                        break;

                    }

                    else

                    {

                        needUpdate = NO;

                        break;

                    }

                }

                

                if (needUpdate) {

                    //弹提示框

                    NSLog(@"弹提示框");

                    SVAlertView *alertView = [[SVAlertView alloc] init];

                    [alertView

                     showAlertViewWithMessage:ReleaseNotes

                     andTitle:@"升级提示"

                     confirmTitle:@"马上更新"

                     cancelTitle:@"以后再说"

                     ConfirmAction:^{

                         NSLog(@"跳到appstore");

                         //跳到appstore

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

                     }

                     andCancelAction:^{

                         NSLog(@"点击了取消");

                     }];

                }

            } failure:^(NSError *error) {

                [MyHUD showInView:ShareApp.window text:@"版本号获取失败"];

                NSLog(@"error:%@",error);

            }];

        });

    }

  • 相关阅读:
    js函数和变量的执行顺序【易错】
    JavaScript实现对象的深度克隆及typeof和instanceof【简洁】【分享】
    java数组与字符串相互转换、整型与字符串相互转换【详解】
    Math对象常用方法(取整细节)
    不使用临时变量互换两个变量的值
    python discover 函数介绍
    Appium+python 一个简单的登录测试实例
    IOS-优质应用推荐
    Appium+Python 自动化-appium常用元素定位方法
    Python+Selenium 自动化实现实例-单元测试报告
  • 原文地址:https://www.cnblogs.com/wangbinios/p/8431832.html
Copyright © 2011-2022 走看看