關(guān)于iOS版本升級(jí),蘋果是不允許用戶有強(qiáng)制用戶升級(jí)的提示的,但是為了讓用戶知道APP更新了残黑,一般APP里面是會(huì)有版本升級(jí)提示。下面來(lái)介紹一下一般都是怎么做的斋否。
方法一:
可以訪問(wèn)itunes拿到iTunes里面的APP版本號(hào)梨水,然后與本地的APP版本號(hào)進(jìn)行對(duì)比,就可以判斷出是否需要升級(jí)了
優(yōu)點(diǎn):不需要對(duì)自己的服務(wù)器進(jìn)行任何操作
缺點(diǎn):訪問(wèn)itunes會(huì)比較慢茵臭,所以請(qǐng)求響應(yīng)時(shí)間會(huì)比較長(zhǎng)
請(qǐng)求網(wǎng)址:
這個(gè)會(huì)返回你的APP在App Store的所有信息
//這個(gè)就是請(qǐng)求后拿到的App Store的版本號(hào)
NSString *appStoreVersion = [responseObject[@"results"] lastObject][@"version"];
//獲取當(dāng)前的APP的版本號(hào)
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
把兩個(gè)版本號(hào)進(jìn)行判斷,注意不能直接轉(zhuǎn)化為double類型
[appStoreVersion compare:appVersion options:NSNumericSearch] == NSOrderedDescending
if ([appStoreVersion compare:appVersion options:NSNumericSearch] == NSOrderedDescending) {//需要升級(jí)
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"溫馨提示" message:@"請(qǐng)升級(jí)版本" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"升級(jí)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *str = @"itms-apps://itunes.apple.com/app/id1228061385";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertVC addAction:sure];
[alertVC addAction:cancel];
[self presentViewController:alertVC animated:YES completion:nil];
}else{//不需要升級(jí)
NSLog(@"不要升級(jí)");
}
方法二:
往自己的服務(wù)器上發(fā)一個(gè)請(qǐng)求疫诽,獲取最新的版本號(hào)與本地的APP版本號(hào)進(jìn)行判斷
優(yōu)點(diǎn):因?yàn)樵L問(wèn)的是自己的服務(wù)器,所以響應(yīng)快
缺點(diǎn):需要自己的服務(wù)器去做對(duì)應(yīng)的接口和數(shù)據(jù)