iOS 自动检测版本更新APP
来源:互联网 发布:如何设置javascript 编辑:程序博客网 时间:2024/05/19 00:15
//联系人:石虎 QQ:1224614774 昵称:嗡嘛呢叭咪哄
一、实现思路
/** 实现思路
1.获取当前项目APP版本号
2.拿到AppStore项目版本号
3.对比版本号,实现更新功能
*/
//一定要先配置自己项目在商店的APPID,配置完最好在真机上运行才能看到完全效果哦
#define STOREAPPID @"1234567890"
二、代码实现
//检测app更新
-(void)updateApp
{
//1.先获取当前工程项目版本号
NSDictionary *infoDic = [[NSBundlemainBundle]infoDictionary];
NSString *currentVersion = infoDic[@"CFBundleShortVersionString"];
//2.从网络获取appStore版本号
NSError *error;
NSData *response = [NSURLConnectionsendSynchronousRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:[NSStringstringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",STOREAPPID]]]returningResponse:nilerror:nil];
//2.1没有内容
if (response == nil) {
NSLog(@"你没有连接网络哦");
return;
}
//3.序列化解析
NSDictionary *appInfoDic = [NSJSONSerializationJSONObjectWithData:responseoptions:NSJSONReadingMutableLeaveserror:&error];
//3.1数据错误
if (error) {
NSLog(@"hsUpdateAppError:%@",error);
return;
}
//3.2字典解析
NSArray *array = appInfoDic[@"results"];
NSDictionary *dic = array[0];
NSString *appStoreVersion = dic[@"version"];
//打印版本号
NSLog(@"当前版本号:%@\n商店版本号:%@",currentVersion,appStoreVersion);
//4.当前版本号小于商店版本号,就更新
if([currentVersion floatValue] < [appStoreVersion floatValue])
{
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"版本有更新" message:[NSStringstringWithFormat:@"检测到新版本(%@),是否更新?",appStoreVersion] delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
[alert show];
}else{
NSLog(@"检测到不需要更新");
}
}
谢谢!!!
- iOS 自动检测版本更新APP
- iOS app自动检测版本更新的功能
- iOS自动检测版本更新
- ios app 版本更新
- iOS APP版本更新
- iOS App版本更新
- IOS App版本更新
- iOS 开发笔记 - 开发中如何实现自动检测更新APP
- ios自动检测更新
- 06.iOS自动检测更新
- 轻松实现APP自动检测更新
- Android 自动检测更新apk版本
- 自动检测更新apk版本问
- 自动检测版本更新的流程
- ios App store版本更新
- ios app如何更新版本
- App检测版本更新 iOS
- iOS App检测版本更新
- 短信监听器
- HTML5小游戏飞机大战
- SEI-CERT Java编程规范(Thread Apis)-不要调用Thread.run()
- linux终端通信write、wall、mesg
- IO流(6)--录入文件路径,拷贝此文件到当前项目
- iOS 自动检测版本更新APP
- LeetCode练习记录2017/12/10
- iOS 播放音频的几种方式
- iOS开发UI篇—Quartz2D(自定义UIImageView控件)
- 忘记svn密码?-快速找回
- 交通工具
- 4---------最小生成树--prim算法
- bzoj 1770: [Usaco2009 Nov]lights 燈
- 单例模式Singleton