app版本更新, 提醒
2016-02-23 15:43
260 查看
/**
*
检测版本升级需要用到的参数 , 在appdelegate里边填写
*/
iFeverAPPID = @"1076057848”;
//appId;
//调用检测版本更新的方法
[self checkVersion];
*
* 检测软件是否需要升级
*/
-(void)checkVersion
{
//获取当前应用版本号
NSDictionary
*appInfo = [[NSBundle
mainBundle]
infoDictionary];
NSString
*currentVersion = [appInfo
objectForKey:@"CFBundleVersion"];
//
用__block才能在局部作用域中改变变量的值
__block
NSString *newVersion =
@"";
NSString
*updateUrlString = [NSString
stringWithFormat:@"http://itunes.apple.com/lookup?id=%ld",(long)[iFeverAPPID
integerValue]];
NSString
* str = [updateUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFHTTPRequestOperationManager
*manager = [AFHTTPRequestOperationManager
manager];
[manager GET:str
parameters:nil
success:^(AFHTTPRequestOperation
*operation,
id responseObject) {
NSLog(@"123 + %@", operation);
NSDictionary
*resultDic = responseObject;
NSArray
*resultArray = [resultDic
objectForKey:@"results"];
for
(id
config in
resultArray) {
newVersion = [config
valueForKey:@"version"];
}
if
(newVersion) {
NSLog(@"通过AppStore获取的版本号是:%@",
newVersion);
}
if
([newVersion floatValue] > [currentVersion
floatValue]) {
NSString
*versionMessageStr = [NSString
stringWithFormat:@"当前版本%@,最新版本为%@,请升级.",currentVersion,newVersion];
UIAlertView
*alert = [[UIAlertView
alloc]
initWithTitle:@"升级提示!"
message: versionMessageStr
delegate:self
cancelButtonTitle:@"下次再说"
otherButtonTitles:@"现在升级",
nil];
alert.tag
=
kVersionNeedUpdateAlertTag;
[alert show];
}
} failure:^(AFHTTPRequestOperation
*operation,
NSError *error) {
NSLog(@"234 + %@", error);
}];
}
#pragma mark - UIAlertDelegate Method
//收到推送时程序正在前台运行,则给出一个alert,用户选择查看,执行这个方法,并且跳转到指定页面
-(void)alertView:(UIAlertView
*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if
(buttonIndex == 1) {
//软件需要更新提醒
if
(alertView.tag
== kVersionNeedUpdateAlertTag) {
NSURL
*url = [NSURL
URLWithString:[NSString
stringWithFormat:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%@?mt=8",iFeverAPPID]];
[[UIApplication sharedApplication]openURL:url];
}
}
}
*
检测版本升级需要用到的参数 , 在appdelegate里边填写
*/
iFeverAPPID = @"1076057848”;
//appId;
//调用检测版本更新的方法
[self checkVersion];
*
* 检测软件是否需要升级
*/
-(void)checkVersion
{
//获取当前应用版本号
NSDictionary
*appInfo = [[NSBundle
mainBundle]
infoDictionary];
NSString
*currentVersion = [appInfo
objectForKey:@"CFBundleVersion"];
//
用__block才能在局部作用域中改变变量的值
__block
NSString *newVersion =
@"";
NSString
*updateUrlString = [NSString
stringWithFormat:@"http://itunes.apple.com/lookup?id=%ld",(long)[iFeverAPPID
integerValue]];
NSString
* str = [updateUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFHTTPRequestOperationManager
*manager = [AFHTTPRequestOperationManager
manager];
[manager GET:str
parameters:nil
success:^(AFHTTPRequestOperation
*operation,
id responseObject) {
NSLog(@"123 + %@", operation);
NSDictionary
*resultDic = responseObject;
NSArray
*resultArray = [resultDic
objectForKey:@"results"];
for
(id
config in
resultArray) {
newVersion = [config
valueForKey:@"version"];
}
if
(newVersion) {
NSLog(@"通过AppStore获取的版本号是:%@",
newVersion);
}
if
([newVersion floatValue] > [currentVersion
floatValue]) {
NSString
*versionMessageStr = [NSString
stringWithFormat:@"当前版本%@,最新版本为%@,请升级.",currentVersion,newVersion];
UIAlertView
*alert = [[UIAlertView
alloc]
initWithTitle:@"升级提示!"
message: versionMessageStr
delegate:self
cancelButtonTitle:@"下次再说"
otherButtonTitles:@"现在升级",
nil];
alert.tag
=
kVersionNeedUpdateAlertTag;
[alert show];
}
} failure:^(AFHTTPRequestOperation
*operation,
NSError *error) {
NSLog(@"234 + %@", error);
}];
}
#pragma mark - UIAlertDelegate Method
//收到推送时程序正在前台运行,则给出一个alert,用户选择查看,执行这个方法,并且跳转到指定页面
-(void)alertView:(UIAlertView
*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if
(buttonIndex == 1) {
//软件需要更新提醒
if
(alertView.tag
== kVersionNeedUpdateAlertTag) {
NSURL
*url = [NSURL
URLWithString:[NSString
stringWithFormat:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%@?mt=8",iFeverAPPID]];
[[UIApplication sharedApplication]openURL:url];
}
}
}
相关文章推荐
- iOS开发之路--微博“更多”页面
- iOS开发之路--微博骨架搭建
- iOS开发使用JSON解析网络数据
- IOS开发代码分享之获取启动画面图片的string
- iOS开发使用XML解析网络数据
- IOS开发之路--C语言数组和字符串
- IOS开发代码分享之用nstimer实现倒计时功能
- iOS开发使用GDataXML框架解析网络数据
- IOS开发代码分享之设置UISearchBar的背景颜色
- iOS和tvOS游戏按需加载资源简介
- ios开发之环境搭建-01
- 在开发iOS程序时对日期处理的总结
- iOS开发——keychain的使用
- iOS Graphics Technologies iOS 图形技术
- iOS开发异常错误总结
- 学习Objective-C:入门手册
- iOS开发 简单实现视频音频的边下边播
- 初学ios开发之iOS 证书、描述文件、AppID
- iOS开发 — Quartz 2D知识点应用 (制作了一个Demo,源代码)