這個方式是從后臺獲取版本號,在蘋果審核期間,保持接口返回數(shù)據(jù)是沒有版本更新的信息,審核通過之后,后臺修改接口返回的數(shù)據(jù),有新版本,ios端彈窗提示版本更新,跳轉至App Store。
網(wǎng)絡請求獲取接口返回的信息(版本號:Versions)
//2.先獲取當前app的版本號
NSString * currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
NSLog(@"當前版本號currentVersion:%@",currentVersion);
//此處截取兩位 是不好控制版本號,version我寫的三位數(shù)
NSString *strCut =[currentVersion substringToIndex:3];
NSLog(@"截取版本號兩位數(shù)strCut:%@",strCut);
NSMutableDictionary *parat =[NSMutableDictionary dictionary];
[parat setValue:@"2" forKey:@"Type"];
[parat setValue:@"IsNew" forKey:@"Versions"];
[[TourExNetWorking shareNetWorking] postRequestWithURL:@"Down.ashx" parameters:parat successBlock:^(id responseObject) {
NSLog(@"responseObject:%@",responseObject);
if (![[[responseObject objectForKey:@"tableName"] objectForKey:@"Versions"] isEqualToString:strCut]) {
NSLog(@"沒有版本更新");
NSUserDefaults *useDef = [NSUserDefaults standardUserDefaults];
// 使用 NSUserDefaults 讀取用戶數(shù)據(jù)
if (![useDef boolForKey:@"notFirst"]) {
// 如果是第一次進入引導頁
_window.rootViewController = [[myViewController alloc] init];
}else{
//1 判斷是否為登錄狀態(tài)。跳轉至登錄界面
//取Uid
NSUserDefaults *userUid =[NSUserDefaults standardUserDefaults];
[userUid synchronize];
NSString *Uid =[NSString stringWithFormat:@"%@",[userUid objectForKey:@"Uid"]];
int userID =[Uid intValue];
NSLog(@"用戶userID:%d",userID);
// 否則直接進入應用
if (userID <1) {
//用戶沒有登錄,跳轉至登錄界面
HomeViewController *homeVC =[[HomeViewController alloc]init];
ZYSNavigationController *nvHome =[[ZYSNavigationController alloc]initWithRootViewController:homeVC];
self.window.rootViewController =nvHome;
}else{
//用戶已經(jīng)登錄,留在當前界面
}
}
}else{
NSLog(@"有新版本,提示是否更新");
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"檢查到新的版本" message:@"是否更新" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];
alert.delegate =self;
[alert show];
}
} faildBlock:^(NSError *error) {
NSLog(@"error:%@",error);
}];
}