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