zoukankan      html  css  js  c++  java
  • iOS应用自动检查更新提示方法

    NSString *version = @"";
    NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=954270"];
    versionRequest = [ASIFormDataRequest requestWithURL:url];
    [versionRequest setRequestMethod:@"GET"];
    [versionRequest setDelegate:self];
    [versionRequest setTimeOutSeconds:150];
    [versionRequest addRequestHeader:@"Content-Type" value:@"application/json"];
    [versionRequest startSynchronous];

    //Response string of our REST call
    NSString* jsonResponseString = [versionRequest responseString];
    NSDictionary *loginAuthenticationResponse = [jsonResponseString objectFromJSONString];
    NSArray *configData = [loginAuthenticationResponse valueForKey:@"results"];
    for (id config in configData)
    {
      version = [config valueForKey:@"version"];
    }
    //Check your version with the version in app store
    if (![version isEqualToString:[itsUserDefaults objectForKey:@"version"]])
    {
       ProAlertView *createUserResponseAlert = [[ProAlertView alloc] initWithTitle:@"New Version!!" message: @"A new version of app is available to download" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: @"Download", nil];
       [createUserResponseAlert show];
       [createUserResponseAlert release];
    }

    - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
        // the user clicked one of the OK/Cancel buttons
        if (buttonIndex == 1)
        {
            NSString *iTunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=<appid>&mt=8";
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
        }
    }

    请求http://itunes.apple.com/lookup?id=954270返回的数据给出的version为2.3, 与本地客户端版本号比较,即可判断有无更新。

    通过此方法,我们可以在IOS应用当中提示是否有更新,这样可以让用户安装更新更安全的应用。

  • 相关阅读:
    C#模拟百度登录并到指定网站评论回帖(一)
    4张图看明白用户、权限和租户的关系
    我的微服务之路
    IT部门不应该是一个后勤部门
    一个值只有0和1的字段,到底要不要建索引?
    论程序员的自我修养
    RBAC权限管理系统数据模型
    有史以来功能最全,使用最简单的excel导入/导出工具
    一个完全平均分布的固定长度随机数发生器
    基于WCF的RESTFul WebAPI如何对传输内容实现压缩
  • 原文地址:https://www.cnblogs.com/sungk/p/5063099.html
Copyright © 2011-2022 走看看