/**
*检测版本升级需要用到的参数
*/
iFeverAPPID=@"1076057848”; //appId;
//调用检测版本更新的方法
[selfcheckVersion];
*
*检测软件是否需要升级
*/
-(void)checkVersion
{
//获取当前应用版本号
NSDictionary*appInfo = [[NSBundlemainBundle]infoDictionary];
NSString*currentVersion = [appInfoobjectForKey:@"CFBundleVersion"];
//用__block才能在局部作用域中改变变量的值
__blockNSString*newVersion =@"";
NSString*updateUrlString = [NSStringstringWithFormat:@"http://itunes.apple.com/lookup?id=%ld",(long)[iFeverAPPIDintegerValue]];
NSString* str = [updateUrlStringstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFHTTPRequestOperationManager*manager = [AFHTTPRequestOperationManagermanager];
[managerGET:strparameters:nilsuccess:^(AFHTTPRequestOperation*operation,idresponseObject) {
NSLog(@"123 + %@", operation);
NSDictionary*resultDic = responseObject;
NSArray*resultArray = [resultDicobjectForKey:@"results"];
for(idconfiginresultArray) {
newVersion = [configvalueForKey:@"version"];
}
if(newVersion) {
NSLog(@"通过AppStore获取的版本号是:%@", newVersion);
}
result ==1
NSComparisonResultresult = [newVersioncompare:currentVersion];
if(result == 1) { //appstore 版本大于当前版本
NSString*versionMessageStr = [NSStringstringWithFormat:@"当前版本%@,最新版本为%@,请升级.",currentVersion,newVersion];
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"升级提示!"message: versionMessageStrdelegate:selfcancelButtonTitle:@"下次再说"otherButtonTitles:@"现在升级",nil];
alert.tag=kVersionNeedUpdateAlertTag;
[alertshow];
}
}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 = [NSURLURLWithString:[NSStringstringWithFormat:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%@?mt=8",iFeverAPPID]];
[[UIApplicationsharedApplication]openURL:url];
}
}
}