版本迭代更新

#defineKEY @"CFBundleShortVersionString"- (void)judgeCurrentAppStoreVersion

{//1.通過(guò)session請(qǐng)求NSString *str =@"http://itunes.apple.com/lookup?id=414478124";

NSURL*urlStr =[NSURL URLWithString:str];

NSURLRequest*request =[NSURLRequest requestWithURL:urlStr];//2.初始化sessionNSURLSession *session =[NSURLSession sharedSession];

NSURLSessionTask*sessionTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError *_Nullable error) {

NSDictionary*appInfo = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];

NSArray*infoContent = [appInfo objectForKey:@"result"];//2.1商店版本號(hào)NSString *storeVersion = [[infoContent objectAtIndex:0] objectForKey:KEY];

NSLog(@"商店的版本號(hào)是%@", storeVersion);//2.2當(dāng)前客戶端的版本號(hào)NSString *currentVersion =[NSBundle mainBundle].infoDictionary[KEY];

NSLog(@"當(dāng)前版本是%@", currentVersion);//2.3比較當(dāng)前版本號(hào)和商店版本號(hào)if(![currentVersion isEqualToString:storeVersion]) {//新版本//2.4彈窗提示更新UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"有最新版本了,請(qǐng)及時(shí)更新"message:nil preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction*OKAction = [UIAlertAction actionWithTitle:@"確定"style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:APP_STRING]];

}];

UIAlertAction*cancelAction = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleDefault handler:nil];

[alertController addAction:OKAction];

[alertController addAction:cancelAction];

dispatch_async(dispatch_get_main_queue(),{

[self.window.rootViewController presentViewController:alertController animated:YES completion:nil];

});//2.5存儲(chǔ)新版本號(hào)NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];

[defaults setObject:KEY forKey:currentVersion];

[defaults synchronize];

}elseif([currentVersion isEqualToString:storeVersion]){//舊版本}

}];//3.開(kāi)啟任務(wù)[sessionTask resume];

}


ttp://itunes.apple.com/lookup?id=414478124 id為APP在AppStore中的一個(gè)序號(hào)。可以打開(kāi)appstore 點(diǎn)擊一個(gè)app 復(fù)制鏈接即可看到。id 是在你提交信息后,先不要提交審核,

就可以看到id。(PS:我是這樣做的,有更好的可以指正)然后拿到這個(gè)id后可以去代碼里面寫(xiě)了。

解釋?zhuān)?/b>

1.CFBundleShortVersionString表示應(yīng)用程序的發(fā)布版本號(hào),

該版本號(hào)一般由三個(gè)整數(shù)構(gòu)成,第一個(gè)整數(shù)表示有重大的修改版本,例如增加新的功能或重大變化。第二個(gè)版本表示修訂版本,實(shí)現(xiàn)較為突出的特點(diǎn)。第三個(gè)版本表示維護(hù)的版本。

該值不同于 "CFBundleVersion" 標(biāo)識(shí)

2.CFBundleVersion 標(biāo)識(shí)應(yīng)用的內(nèi)部版本號(hào)

這個(gè)版本是內(nèi)部自己團(tuán)隊(duì)使用的一個(gè)版本號(hào),一般不對(duì)外公開(kāi)。

這兩個(gè)的區(qū)別:

1. CFBundleShortVersionString對(duì)應(yīng)Xcode里項(xiàng)目的Version

2. CFBundleVersion對(duì)應(yīng)Xcode里項(xiàng)目的Build

每發(fā)布一個(gè)新應(yīng)用或新版本,蘋(píng)果都要求你輸入一個(gè)版本號(hào),這個(gè)版本號(hào)對(duì)應(yīng)的是CFBundleShortVersionString,不要寫(xiě)錯(cuò)哦。并且,如果你上傳成功后(未審核,或未通過(guò)),然后又修復(fù)了bug,或改了功能,那么在打包發(fā)布時(shí),CFBundleVersion必須比上一版本更大。

打個(gè)比方,我第一次上傳的Version:1.5.1、Build:3.4.2 ,那我這個(gè)應(yīng)用被拒絕,修復(fù)好后,我又打包上傳時(shí),Version還是1.5.1,但Build必須大于3.4.2,可以是3.4.3 、3.4.5、3.8.5等。 如果Version 1.5.1通過(guò)審核后,又發(fā)新版本,那個(gè)下次上傳時(shí),Version要大于1.5.1,但Build可以從新開(kāi)始,比如1.1.0 。如果Version1.5.1又有問(wèn)題,我又要上傳修改后的應(yīng)用時(shí),Build必須大于上一個(gè)上傳成功的Build,即要大于1.1.0。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容