#pragma mark 版本檢測 版本升級提示
+(void)judgeAppVersionAndShowNoticeWithView:(UIViewController*)view withAppId:(NSString*)appId
{
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//當前App 標示Id
NSString *urlStr = [NSString stringWithFormat:@"%@%@", Judge_AppVersion, appId];
[HttpUtil sendGetRequestWithUrl:urlStr complete:^(NSError *error, NSDictionary *objectDic) {
[GCDQueue executeInMainQueue:^{
debugLog(@"獲取版本信息:%@", objectDic);
NSInteger resultCount = [[objectDic objectForKey:@"resultCount"]integerValue];
if (resultCount>=1) {
NSDictionary *results = [[objectDic objectForKey:@"results"]objectAtIndex:0];
NSString *version = [results objectForKey:@"version"];
if (version && ![version isKindOfClass:[NSNull class]] && ![version isEqualToString:@""]) {
//版本比較
BOOL isNeedUpdate = [Tool justifyAppStoreVersionString:version withCurrentVersion:currentVersion];
if (isNeedUpdate) {
//有新版本
NSString *str = [NSString stringWithFormat:@"當前有更新版本%@可以使用, 是否前往下載。", version];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:str preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"升級" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//去AppStore更新
NSString *appStoreLink = [NSString stringWithFormat:@"http://itunes.apple.com/cn/app/id%@",appId];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:appStoreLink]];
}];
[alert addAction:cancelAction];
[alert addAction:okAction];
[view presentViewController:alert animated:YES completion:nil];
}
}
}
}];
}];
}
//版本判斷 - 多數(shù)點 數(shù)字判斷
+(BOOL)justifyAppStoreVersionString:(NSString*)version withCurrentVersion:(NSString*)currentVersion
{
int updateFlag = 0; //0:默認相等; 1:當前版本大于AppStore版本; 2:AppStore版本大于當前版本-需要升級;
//分割字符串
NSArray *curentVersionArr = [currentVersion componentsSeparatedByString:@"."]; //當前版本
NSArray *appStoreVersionArr = [version componentsSeparatedByString:@"."]; //比較版本
NSInteger count = curentVersionArr.count>appStoreVersionArr.count?appStoreVersionArr.count:curentVersionArr.count;
for (int i=0; i<count; i++) {
NSInteger curV = [[curentVersionArr objectAtIndex:i] integerValue];
NSInteger appV = [[appStoreVersionArr objectAtIndex:i] integerValue];
if (appV<curV) {
updateFlag = 1;
break;
}else if (appV>curV){
updateFlag = 2;
break;
}
}
if (updateFlag == 0) {
//(2.8.1 與 2.8.1.1)(2.5.3 與 2.5) 這種情況
if (appStoreVersionArr.count>curentVersionArr.count)
{
updateFlag = 2;
}
}
BOOL isNeedUpdate = updateFlag==2?YES:NO;
return isNeedUpdate;
}
iOS 版本檢測-版本升級提示
最后編輯于 :
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門阀溶,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人鸦泳,你說我怎么就攤上這事银锻。” “怎么了做鹰?”我有些...
- 文/不壞的土叔 我叫張陵击纬,是天一觀的道長。 經(jīng)常有香客問我钾麸,道長更振,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任饭尝,我火速辦了婚禮肯腕,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘钥平。我一直安慰自己实撒,他們只是感情好,可當我...
- 文/花漫 我一把揭開白布帖池。 她就那樣靜靜地躺著奈惑,像睡著了一般。 火紅的嫁衣襯著肌膚如雪睡汹。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼秽浇,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了甚负?” 一聲冷哼從身側(cè)響起柬焕,我...
- 正文 年R本政府宣布,位于F島的核電站伐蒋,受9級特大地震影響工三,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜先鱼,卻給世界環(huán)境...
- 文/蒙蒙 一俭正、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧焙畔,春花似錦掸读、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至伸但,卻和暖如春肾请,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背更胖。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 更新于 2018.06.08 好久沒管過簡書了?? 注意:Apple ID 在您在appstoreconnect.a...
- 當你的 app 版本更新之后,一般情況下用戶是不會知道的,只有等到 App Store 的圖標上有一個大大的"1"...
- 如果要在app里加入提醒用戶升級的功能,只需要幾個步驟: 獲取用戶本地app的版本號 獲取App Store上本a...
- 本文主要介紹的是兩種提示用戶的更新的方法薄声,文字比較多当船。但都是邏輯 現(xiàn)在蘋果審核不能看到版本提示更新的字樣以及功能,...