iOS开发之检查更新
生活随笔
收集整理的這篇文章主要介紹了
iOS开发之检查更新
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
iOS設備檢查更新版本:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #pragma mark - 檢查更新 - (void)checkUpdateWithAPPID:(NSString?*)APPID { ????//獲取當前應用版本號 ????NSDictionary?*appInfo = [[NSBundle?mainBundle] infoDictionary];??? ????NSString?*currentVersion = [appInfo objectForKey:@"CFBundleVersion"]; ????? ????NSString?*updateUrlString = [NSString?stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",APPID]; ????NSURL?*updateUrl = [NSURL?URLWithString:updateUrlString]; ????versionRequest = [ASIFormDataRequest requestWithURL:updateUrl]; ????[versionRequest setRequestMethod:@"GET"]; ????[versionRequest setTimeOutSeconds:60]; ????[versionRequest addRequestHeader:@"Content-Type"?value:@"application/json"]; ????? ????//loading view ????CustomAlertView *checkingAlertView = [[CustomAlertView alloc] initWithFrame:NAVIGATION_FRAME style:CustomAlertViewStyleDefault noticeText:@"正在檢查更新..."]; ????checkingAlertView.userInteractionEnabled =?YES; ????[self.navigationController.view addSubview:checkingAlertView]; ????[checkingAlertView release]; ????? ????[versionRequest setCompletionBlock:^{ ????????? ????????[checkingAlertView removeFromSuperview]; ????????? ????????NSError?*error =?nil; ????????NSDictionary?*dict = [NSJSONSerialization?JSONObjectWithData:[versionRequest responseData] options:NSJSONReadingMutableContainers?error:&error]; ????????if?(!error) { ????????????if?(dict !=?nil) { ????????????????//??????????? DLog(@"dict %@",dict); ????????????????int?resultCount = [[dict objectForKey:@"resultCount"] integerValue]; ????????????????if?(resultCount == 1) { ????????????????????NSArray?*resultArray = [dict objectForKey:@"results"]; ????????????????????//??????????????? DLog(@"version %@",[resultArray objectAtIndex:0]); ????????????????????NSDictionary?*resultDict = [resultArray objectAtIndex:0]; ????????????????????//??????????????? DLog(@"version is %@",[resultDict objectForKey:@"version"]); ????????????????????NSString?*newVersion = [resultDict objectForKey:@"version"]; ????????????????????? ????????????????????if?([newVersion doubleValue] > [currentVersion doubleValue]) { ????????????????????????NSString?*msg = [NSString?stringWithFormat:@"最新版本為%@,是否更新?",newVersion]; ????????????????????????newVersionURlString = [[resultDict objectForKey:@"trackViewUrl"]?copy]; ????????????????????????DLog(@"newVersionUrl is %@",newVersionURlString); ????????????????????????//??????????????????? if ([newVersionURlString hasPrefix:@"https"]) { ????????????????????????//???????????????????????? [newVersionURlString replaceCharactersInRange:NSMakeRange(0, 5) withString:@"itms-apps"]; ????????????????????????//??????????????????? } ????????????????????????UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"?message:msg delegate:self?cancelButtonTitle:@"暫不"?otherButtonTitles:@"立即更新",?nil]; ????????????????????????alertView.tag = 1000; ????????????????????????[alertView show]; ????????????????????????[alertView release]; ????????????????????}else ????????????????????{ ????????????????????????UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"?message:@"您使用的是最新版本!"?delegate:self?cancelButtonTitle:nil?otherButtonTitles:@"確定",?nil]; ????????????????????????alertView.tag = 1001; ????????????????????????[alertView show]; ????????????????????????[alertView release]; ????????????????????} ????????????????} ????????????} ????????}else ????????{ ????????????DLog("error is %@",[error debugDescription]); ????????} ????}]; ????? ????[versionRequest setFailedBlock:^{ ????????[checkingAlertView removeFromSuperview]; ????????? ????????CustomAlertView *alertView = [[CustomAlertView alloc] initWithFrame:NAVIGATION_FRAME style:CustomAlertViewStyleWarning noticeText:@"操作失敗,請稍候再試!"]; ????????[self.navigationController.view addSubview:alertView]; ????????[alertView release]; ????????[alertView selfRemoveFromSuperviewAfterSeconds:1.0]; ????}]; ????? ????[versionRequest startSynchronous];? } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { ????DLog(@"newVersionUrl? is %@",newVersionURlString); ????if?(buttonIndex) { ????????if?(alertView.tag == 1000) { ????????????if(newVersionURlString) ????????????{ ????????????????[[UIApplication sharedApplication] openURL:[NSURL?URLWithString:newVersionURlString]]; ????????????} ????????} ????} } |
?
來源:http://blog.csdn.net/heartofthesea/article/details/14127587
本文轉自夏雪冬日博客園博客,原文鏈接:http://www.cnblogs.com/heyonggang/p/3539691.html,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的iOS开发之检查更新的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ECMAScript6 规范
- 下一篇: 安卓WebView加载网页不显示或者乱跳