iOS版本更新

版本更新

#pragma mark -檢查版本更新

- (void)checkNewVersion {

//??? NSString *url = @"https://itunes.apple.com/cn/app/ya-zi-kan-hu-ji-qi-ren/id1067342148?mt=8";

NSString*url =@"http://itunes.apple.com/cn/lookup?id=1067342148";

[GJWHttpTool ? ? ? ? getWithURL:url ? params:nil ? ?success:^(idjson) {

//請(qǐng)求成功

//字典接收請(qǐng)求到的JSon

NSDictionary ? *reslut = [NSJSONSerialization ? ? JSONObjectWithData:json ? ? options:NSJSONReadingMutableContainers ? ?error:nil];

NSDictionary ? *responseDict = [NSDictionary ? ? dictionaryWithDictionary:reslut];

//解析請(qǐng)求到的JSon

NSArray ? *results =[responseDict ? ? ?objectForKey:@"results"];

NSDictionary ? ?*finalDict = [results ? ?firstObject];

//獲取APP下載地址

NSString*trackViewUrl =[finalDict ? ?objectForKey:@"trackViewUrl"];

updateUrl= [NSURL ? ? URLWithString:trackViewUrl];

//獲取官網(wǎng)APP的版本號(hào)

NSString ? *str1 = [finalDict ? ? objectForKey:@"version"];

NSString ? *version1 = [str1 ? ? ?substringFromIndex:2];

//將版本號(hào)字符串轉(zhuǎn)換成float類(lèi)型

floatnewVersion = [version1 ? ? ?floatValue];

//獲取本地項(xiàng)目版本號(hào)

//拿到項(xiàng)目的infoPlist文件中所有內(nèi)容

NSDictionary ?*infoDict = [[NSBundle ? ? mainBundle] ? ?infoDictionary];

//獲取到當(dāng)前工程版本號(hào)

NSString ?*str2 = [infoDict ?objectForKey:@"CFBundleShortVersionString"];

NSString ?*version2 = [str2 ? substringFromIndex:2];

//將版本號(hào)字符串轉(zhuǎn)換成float類(lèi)型

floatlocalVersion =[version2 ? floatValue];

//對(duì)比兩處版本號(hào)

if(newVersion >localVersion) {

UIAlertView ? *alert=[[UIAlertView ? ?alloc] ? ? initWithTitle:@""message:[NSStringstringWithFormat:@"新版本%@已發(fā)布!",str1] ? delegate:self.classcancelButtonTitle:@"知道了"otherButtonTitles:nil,nil];

alert.delegate=self;

[alert ? ? addButtonWithTitle:@"前往更新"];

[alert ? show];

alert.tag=20;

}else{

[[[UIAlertView ? ?alloc] ? ? ?initWithTitle:nilmessage:@"已是最高版本"delegate:self.classcancelButtonTitle:@"知道了"otherButtonTitles:nil,nil]show];

}

}failure:^(NSError*error) {

//返回請(qǐng)求失敗的原因

NSLog(@"NSError:%@", error);

}];

}

#pragma mark – UIAlertViewDelegate

- (void)alertView:(UIAlertView*)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{

if(buttonIndex ==1& alertView.tag==20) {

//??????? NSString*url = @"https://itunes.apple.com/cn/app/ya-zi-kan-hu-ji-qi-ren/id1067342148?mt=8";

//???????[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

[[UIApplication ? ? sharedApplication] ? ? openURL:updateUrl];

}

}

注:不喜勿噴?。?!

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

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

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