zoukankan      html  css  js  c++  java
  • ios 实现版本更新检查

        注:这里网络请求用的是第三方框架:SVHTTPRequest

    /*

      第一步: 根据应用名称搜索应用,然后根据应用绑定的ID在结果中筛选出我们要找的应用,并取出应用的AppID

    */ 

    - (void)getAppID {

        processView  = [[UIProcessViewalloc]initWithFrame:self.view.framewithText:@"检测中..."];

        [processViewstartAnimating];

        [self.viewaddSubview:processView];

        [SVHTTPRequestPOST:@"http://itunes.apple.com/search"

                 parameters:[[NSDictionaryalloc] initWithObjectsAndKeys:APP_NAME,@"term",@"software",@"entity",nil]

                 completion:^(id response, NSHTTPURLResponse *urlResponse, NSError *error) {

                     

                     if (!error&&[urlResponse statusCode]==200) {

                         NSData *data = (NSData *)response;

                         id res = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:nil];

                         NSLog(@"res.class==%@",[res class]);

                         NSLog(@"res == %@",res);

                         NSLog(@"results class == %@",[[res objectForKey:@"results"]class]);

                         NSArray *arr = [res objectForKey:@"results"];

                         for (id config in arr)

                         {

                             NSString *bundle_id = [config valueForKey:@"bundleId"];

                             if ([bundle_id isEqualToString:APP_BUNDLE_IDENTIFIER]) {

                                 [processView stopAnimating];

                                 app_id  = [config valueForKey:@"trackId"];

                                 updateURL = [config valueForKey:@"trackViewUrl"];

                                 NSString *app_Name = [config valueForKey:@"trackName"];

                                 NSString *version = [config valueForKey:@"version"];

                                 NSLog(@"app_id == %@,app_Name == %@,version == %@",app_id,app_Name,version);

                                 [self checkUpdate:version];

                             }

                         }

                     } else {

                         [processView stopAnimating];

                         [CTCommonUtilsshowAlertViewOnView:self.viewwithText:@"检测失败,当前无网络连接!"];

                     }

                 }];

    }

    /*

      第二步:通过比较从App Store获取的应用版本与当前程序中设定的版本是否一致,然后判断版本是否有更新

    */

    - (void)checkUpdate:(NSString *)versionFromAppStroe {

        NSDictionary *infoDict = [[NSBundlemainBundle] infoDictionary];

        NSString *nowVersion = [infoDict objectForKey:@"CFBundleVersion"];

        NSLog(@"nowVersion == %@",nowVersion);

        [processViewstopAnimating];

        //检查当前版本与appstore的版本是否一致

        if (![versionFromAppStroe isEqualToString:nowVersion])

        {

            UIAlertView *createUserResponseAlert = [[UIAlertView alloc] initWithTitle:@"提示" message: @"有新的版本可供下载" delegate:self cancelButtonTitle:@"下次再说" otherButtonTitles: @"去下载", nil];

            [createUserResponseAlert show];

        } else {

            [CTCommonUtilsshowAlertViewOnView:self.viewwithText:@"暂无新版本"];

        }

    }

    #pragma mark - AertView delegate

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

    {

        if (buttonIndex == 1) {

       //去appstore中更新

            //方法一:根据应用的id打开appstore,并跳转到应用下载页面

            //NSString *appStoreLink = [NSString stringWithFormat:@"http://itunes.apple.com/cn/app/id%@",app_id];

            //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStoreLink]];

            

            //方法二:直接通过获取到的url打开应用在appstore,并跳转到应用下载页面

            [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:updateURL]];

     

        } else if (buttonIndex == 2) {

            //去itunes中更新

            [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"itms://itunes.apple.com/cn/app/guang-dian-bi-zhi/id511587202?mt=8"]];

        }

    }

    #pragma mark -

  • 相关阅读:
    HTML/CSS基础教程 一
    linux鼠标闪烁问题解决
    Linux运行级别(runlevel)
    linux命令——umask
    linux命令——ulimit
    算法学习(二)——二分查找
    c++(一) :从c到c++
    shell编程(二)输入,输出和算术拓展
    shell编程(一)基础
    第二次Soring冲刺计划第一天(团队)
  • 原文地址:https://www.cnblogs.com/weilaikeji/p/3331772.html
Copyright © 2011-2022 走看看