標籤:
1.軟體中需要自己在後台伺服器中,設定新的版本號碼。每次登陸軟體從後台拉取資料,用最新版本號碼與目前的版本號進行比較。實現軟體更新。
2.每次登陸軟體從蘋果伺服器拉取資料,用最新版本號碼與目前的版本號進行比較。實現軟體更新。
第一種檢測更新方法的優點是:檢測更新速度快、檢測穩定;缺點是:和app store上的應用版本號碼不同步(app上架需要審核時間,不確定什麼時候成功更新到app store上)。第二種方法檢測更新方法的優點是:檢測版本號碼是即時同步的;缺點是:蘋果網路不穩定,檢測更新延時嚴重,部分APP擷取不到任何參數。
個人喜歡使用第一種,只需要後台伺服器根據app store上架版本號碼手動修改資料就行了,APP版本號碼格式也可以自己定義。
代碼如下:
#pragma mark--擷取最新版本
- (void)getNewVerion
{ // 1.取得介面字串
NSString *getInformation = K_AppInfo;
// 2.擷取資料
[UpDataDataService requestData:getInformation withResult:^(id result) {
NSDictionary *information = [result objectForKey:@"results"][0];
// 1)擷取最新版本
NSString *newVersion = [information objectForKey:@"version"];
// 2)擷取目前的版本
NSString *nowVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSString *message = [[NSString alloc] initWithFormat:@"****最新版本:%@,為了不影響您的使用,請儘快更新!",newVersion];
// 3)判斷最新版本是否大於目前的版本
if ([newVersion integerValue]>[nowVersion integerValue])
{ // 4)在非同步呼叫中對UI設定必須回調到主線程
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@"提示更新" message:message delegate:self cancelButtonTitle:@"取消更新" otherButtonTitles:@"確定更新", nil];
[alerView show];
});
}
}];
}
iOS軟體更新問題