惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - Longkin

ios9+xcode7 适配笔记 xsd、wsdl生成C#类的命令行工具使用方法 xcode更新,想想也是醉了 关于#define预处理指令的一个问题 UITextField实现左侧空出一定的边距 IOS动态判断UITextField是否输入为手机号 我的第二个app上线:术购管家 百度地图 IOS版开发经验分享 最新app store 应用提交经验分享 用C#做的软件界面 由windows server2012 想起 关于团队合作的一点认识 由“美图秀秀”软件的网站,看网站的生存模式 下个月计划【2009-5】 对新网好失望,郁闷中 如何实现asp.net页面的美观性? 关于UpdatePanel和页面刷新的问题 新手看SEO网站优化 转载---Web 2.0 新名词:Widget
IOS判断app在appstore是否有可用的更新
Longkin · 2014-12-12 · via 博客园 - Longkin

iTunes可以提供app的版本信息,主要通过appid获取,如 http://itunes.apple.com/lookup?id=946449501,使用时只需要到iTunes查找自己的appid,修改成自己的appid即可

使用HTTP模式读取此链接可以获取app信息的json字符串

贴出部分代码

-(void)checkVersion
{
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]];//strURL为你的appid地址
    [request setRequestMethod:@"POST"];
    [request setDelegate:self];
    [request startAsynchronous];
}

-(void)requestFinished:(ASIHTTPRequest *)request
{
    NSString *recStr = [[NSString alloc] initWithData:request.responseData encoding:NSUTF8StringEncoding];
    recStr = [recStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];//返回的字符串有前面有很多换行符,需要去除一下
    NSDictionary *resultDic = [JSONHelper DeserializerDictionary:recStr];//jsonhelper是我封装的json解析类,你可以使用自己方式解析
    
    NSArray *infoArray = [resultDic objectForKey:@"results"];
    if (infoArray.count > 0) {
        
        NSDictionary* releaseInfo =[infoArray objectAtIndex:0];
        NSString* appStoreVersion = [releaseInfo objectForKey:@"version"];
        NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
        NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
        
        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) {
                needUpdate = YES;
                break;
            }
        }
        
        //如果有可用的更新
        if (needUpdate){
            
            trackViewURL = [[NSString alloc] initWithString:[releaseInfo objectForKey:@"trackViewUrl"]];//trackViewURL临时变量存储app下载地址,可以让app跳转到appstore
            UIAlertView* alertview =[[UIAlertView alloc] initWithTitle:@"版本升级" message:[NSString stringWithFormat:@"发现有新版本,是否升级?"] delegate:self cancelButtonTitle:@"暂不升级" otherButtonTitles:@"马上升级", nil];
            [alertview show];
            
        }
        
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1){
        UIApplication *application = [UIApplication sharedApplication];
        [application openURL:[NSURL URLWithString:trackViewURL]];
    }
}