/**
*檢測版本升級需要用到的參數
*/
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];
}
}
}