博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
应用在AppStore检测版本更新
阅读量:4984 次
发布时间:2019-06-12

本文共 4489 字,大约阅读时间需要 14 分钟。

 

// appstore的情况下,版本检查升级的处理

 
 

#define  kShiperAppID     @"AppStore中查看AppId" 

 

#define  kURLLookup   @"http://itunes.apple.com/cn/lookup?id=%@"

#pragma mark - appStore检查更新- (void)checkUpdate:(id)sender{        __weak typeof(self) wself = self;    [MBProgressHUD showHUDAddedTo:self.window animated:YES];    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(){        //        NSString *url = [NSString stringWithFormat:kURLLookup,@"423084029"];        //        if ([self.type isEqualToString:@"shipper"]) {
NSString *url = [NSString stringWithFormat:kURLLookup,kShiperAppID]; // } NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:url]]; [request setHTTPMethod:@"GET"]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSDictionary *result = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:nil]; NSString *serverV = @""; NSString *serVInfo = @""; do { if (!result){ break; } id ary = result[@"results"]; if (!ary || NO == [ary isKindOfClass:[NSArray class]]) { break; } if ([(NSArray*)ary count] <= 0) { break; } NSDictionary* dict = ary[0]; if (!dict) { break; } serverV = [dict objectForKey:@"version"]; serVInfo = [dict objectForKey:@"releaseNotes"]; }while (NO); dispatch_async(dispatch_get_main_queue(), ^(){ [MBProgressHUD hideAllHUDsForView:wself.window animated:YES]; NSString* currver = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; if ([currver length] == 0) { currver = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; } if (serverV.length > 0 && NSOrderedDescending == [self verseionCompare:currver ver2compare:serverV]) { NSString* tipmsg = [NSString stringWithFormat:@"发现新版:%@\r\n%@",serverV,serVInfo]; UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:tipmsg delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"更新",nil]; [alert show]; }else{
//如果是最新版本则不提醒 // [self showMessageWith:@"您当前的版本已是最新版本"]; // NSString* tipmsg = [NSString stringWithFormat:@"发现新版:%@\r\n%@",serverV,serVInfo]; // // UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil // message:tipmsg // delegate:self // cancelButtonTitle:@"取消" // otherButtonTitles:@"更新",nil]; // [alert show]; } }); });}
-(NSComparisonResult)verseionCompare:(NSString*)curversion ver2compare:(NSString*)ver2compare{    NSString* curV = [curversion stringByReplacingOccurrencesOfString:@"." withString:@""];    NSString* V2cp = [ver2compare stringByReplacingOccurrencesOfString:@"." withString:@""];        if ([curV integerValue] == [V2cp integerValue]) {        return NSOrderedSame;    }    if ([curV integerValue] < [V2cp integerValue]) {        return NSOrderedDescending;    }    if ([curV integerValue] > [V2cp integerValue]) {        return NSOrderedAscending;    }    return NSOrderedSame;}
#pragma mark - AlertView Delegate- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    if (buttonIndex == 0) {        NSLog(@"quxiao");    }else{        NSLog(@"gengxin");         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/app/id%@",kShiperAppID]]];      }}

 

转载于:https://www.cnblogs.com/h-tao/p/5045367.html

你可能感兴趣的文章
希尔排序与快速排序
查看>>
洛谷p1966 火柴排队 (逆序对变形,目标排序
查看>>
SAE中Python无法创建多线程的解决方案
查看>>
Linux用户管理
查看>>
js-select
查看>>
django models中字段
查看>>
AutoCAD的一些优化设置
查看>>
Raspberry Pi中可用的Go IDE:liteide
查看>>
20165310 NetSec2019 Week5 Exp3 免杀原理与实践
查看>>
Meta标签详解(HTML JAVASCRIPT)
查看>>
Sass用法指南
查看>>
MSP430 ADC12模块(转)
查看>>
jquery基础
查看>>
TCP/IP协议三次握手与四次挥手
查看>>
Mars-Android学习——网络文件下载和写入SD卡
查看>>
jQuery validate兼容IE8写法
查看>>
JSP中include的两种方法
查看>>
Ubuntu使用总结
查看>>
2019春第六周编程总结
查看>>
FLASH组件在FLEX中使用
查看>>