app更新

作者: 哭泣男孩儿 | 来源:发表于2017-12-25 10:08 被阅读9次

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]];

}

}

相关文章

  • app更新

    iTunes可以提供app的版本信息,主要通过appid获取,如http://itunes.apple.com/l...

  • app更新

  • app更新

    uniapp自动更新 本文只讲述Android的更新。静默更新,市场更新,静默下载等都可参照思路发挥。 配置更新页...

  • App 版本更新

    App更新流程:检查更新==>提示更新==>下载apk==>安装新版App 检查更新:根据不同的业务和后台逻辑实现...

  • (App 更新)App Update

    App Update 这个插件可以自动更新androidRepo(备用): https://github.com/...

  • App提示更新bug

    问题描述:App提示更新,但是等更新以后发现实际根本没更新,还是原先的版本,App还是在提示更新,结果继续更新,等...

  • App Store显示"我们无法完成您的购物操作"

    Mac电脑上,在App Store中更新App。在网络良好的情况下,App Store无法更新App,显示出错信息...

  • 无法下载app

    最近为了更新Xcode,更新了系统OS X10.14,之后发现app store更新,下载不了app,根据网上资料...

  • app“热更新”将被苹果商店下架?拼多多就是最好的例子!

    导读:什么是热更新?事实上,“热更新”一般是众多手游app常用的更新方式,即用户通过App Ste下载App之后,...

  • 【Android开发学Flutter】APP检查更新

    APP检查更新基本上是所有APP必备的功能,除了应用市场的提示更新之外,我们还希望APP有应用内检查更新功能,方便...

网友评论

      本文标题:app更新

      本文链接:https://www.haomeiwen.com/subject/cqpcdttx.html