iOS开发app自动更新的实现
#define kStoreAppId @“xxxxxxxxx” // (appid数字串)
-(void)checkAppUpdate {
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *nowVersion = [infoDict objectForKey:@"CFBundleVersion"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", kStoreAppId]];
NSString * file = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSRange substr = [file rangeOfString:@"\"version\":\""]; NSRange range1 = NSMakeRange(substr.location+substr.length,10);
NSRange substr2 =[file rangeOfString:@"\"" options:nil range:range1]; NSRange range2 = NSMakeRange(substr.location+substr.length, substr2.location-substr.location-substr.length);
NSString *newVersion =[file substringWithRange:range2];
if(![nowVersion isEqualToString:newVersion]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"版本有更新"delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil]; [alert show];
}
}
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==1)
{ // 此处加入应用在app store的地址,方便用户去更新,一种实现方式如下:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", kStoreAppId]];
[[UIApplication sharedApplication] openURL:url]; } }
最新文章
- .NET Core RC2/RTM 明确了时间表
- [LeetCode] Candy 分糖果问题
- NopCommerce 增加 Customer Attributes
- python成长之路【第十四篇】:HTML初步认识
- ubuntu 下更新PHP版本 ZT
- Linux_03------Linux的基本命令
- SDUT1479数据结构实验之栈:行编辑器
- codeforces300A Array
- Java基础知识强化之IO流笔记58:内存操作流
- json 序列化的两种方式
- C# 的sql server like 的参数
- SSH框架完全整合
- STL 贺习笔记
- Laravel - Union + Paginate at the same time? and another problem----1222 The used SELECT statements have a different number of columns (SQL: (select count(*) as aggregate from
- openstack 之~keystone基础
- Django基本配置与URLconf
- stm32最简单的实现BootLoader
- 自定义Exception:MVC抛出自定义异常,并以Json方式返回
- Azure SQL 数据库仓库Data Warehouse (2) 架构
- 深入出不来nodejs源码-从fs.stat方法来看node架构