/**
* 检测版本升级需要用到的参数
*/
* 检测版本升级需要用到的参数
*/
iFeverAPPID = @"1076057848”; //appId;
//调用检测版本更新的方法
[selfcheckVersion];
*
* 检测软件是否需要升级
*/
-(void)checkVersion
{
//获取当前应用版本号
NSDictionary *appInfo = [[NSBundlemainBundle] infoDictionary];
NSString *currentVersion = [appInfoobjectForKey:@"CFBundleVersion"];
// 用__block才能在局部作用域中改变变量的值
__block NSString *newVersion = @"";
NSString *updateUrlString = [NSStringstringWithFormat:@"http://itunes.apple.com/lookup?id=%ld",(long)[iFeverAPPIDintegerValue]];
NSString * str = [updateUrlStringstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];
[manager GET:str parameters:nil success:^(AFHTTPRequestOperation*operation, id responseObject) {
NSLog(@"123 + %@", operation);
NSDictionary *resultDic = responseObject;
NSArray *resultArray = [resultDicobjectForKey:@"results"];
for (idconfig in resultArray) {
newVersion = [config valueForKey:@"version"];
}
if (newVersion) {
NSLog(@"通过AppStore获取的版本号是:%@", newVersion);
}
* 检测软件是否需要升级
*/
-(void)checkVersion
{
//获取当前应用版本号
NSDictionary *appInfo = [[NSBundlemainBundle] infoDictionary];
NSString *currentVersion = [appInfoobjectForKey:@"CFBundleVersion"];
// 用__block才能在局部作用域中改变变量的值
__block NSString *newVersion = @"";
NSString *updateUrlString = [NSStringstringWithFormat:@"http://itunes.apple.com/lookup?id=%ld",(long)[iFeverAPPIDintegerValue]];
NSString * str = [updateUrlStringstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];
[manager GET:str parameters:nil success:^(AFHTTPRequestOperation*operation, id responseObject) {
NSLog(@"123 + %@", operation);
NSDictionary *resultDic = responseObject;
NSArray *resultArray = [resultDicobjectForKey:@"results"];
for (idconfig in resultArray) {
newVersion = [config valueForKey:@"version"];
}
if (newVersion) {
NSLog(@"通过AppStore获取的版本号是:%@", newVersion);
}
result == 1
NSComparisonResult result = [newVersion compare:currentVersion];
if ( result == 1 ) { //appstore 版本大于当前版本
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 ]];
[[UIApplicationsharedApplication]openURL:url];
}
}
}
}