iOS提示用戶新版本更新(不從App Store獲取版本信息)

這個方式是從后臺獲取版本號,在蘋果審核期間,保持接口返回數(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);

}];

}

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容