iOS app版本监测升级
2016-06-08 09:09
274 查看
//从Appstore监测版本
-(void)onCheckVersion
{
//本地短版本号
NSDictionary *infoDic = [[NSBundlemainBundle]
infoDictionary];
//CFShow((__bridge CFTypeRef)(infoDic));
NSString *currentVersion = [infoDic
objectForKey:@"CFBundleShortVersionString"];
//itunes版本号
NSString *URL =@"http://itunes.apple.com/lookup?id=1102364142";
NSMutableURLRequest *request = [[NSMutableURLRequestalloc]
init];
[request setURL:[NSURLURLWithString:URL]];
[request setHTTPMethod:@"POST"];
NSHTTPURLResponse *urlResponse =
nil;
NSError *error =
nil;
NSData *recervedData = [NSURLConnectionsendSynchronousRequest:request
returningResponse:&urlResponse
error:&error];
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:recervedData
options:kNilOptionserror:&error];
NSArray *infoArray = [dic
objectForKey:@"results"];
if ([infoArray
count]) {
NSDictionary *releaseInfo = [infoArrayobjectAtIndex:0];
NSString *lastVersion = [releaseInfo
objectForKey:@"version"];
if (![lastVersion
isEqualToString:currentVersion]) {
UIAlertView *alert = [[UIAlertViewalloc]
initWithTitle:@"更新"message:@"有新的版本更新,是否前往更新?"delegate:selfcancelButtonTitle:@"关闭"otherButtonTitles:@"更新",nil];
alert.tag =
10000;
[alert show];
}
}
}
//更新地址
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag==10000) {
if (buttonIndex==1) {
NSURL *url = [NSURLURLWithString:@"https://itunes.apple.com/us/app/coband/id1102364142?mt=8"];
下载地址类似:http://itunes.apple.com/app/id1166090758
[[UIApplicationsharedApplication]openURL:url];
}
}
}
-(void)onCheckVersion
{
//本地短版本号
NSDictionary *infoDic = [[NSBundlemainBundle]
infoDictionary];
//CFShow((__bridge CFTypeRef)(infoDic));
NSString *currentVersion = [infoDic
objectForKey:@"CFBundleShortVersionString"];
//itunes版本号
NSString *URL =@"http://itunes.apple.com/lookup?id=1102364142";
NSMutableURLRequest *request = [[NSMutableURLRequestalloc]
init];
[request setURL:[NSURLURLWithString:URL]];
[request setHTTPMethod:@"POST"];
NSHTTPURLResponse *urlResponse =
nil;
NSError *error =
nil;
NSData *recervedData = [NSURLConnectionsendSynchronousRequest:request
returningResponse:&urlResponse
error:&error];
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:recervedData
options:kNilOptionserror:&error];
NSArray *infoArray = [dic
objectForKey:@"results"];
if ([infoArray
count]) {
NSDictionary *releaseInfo = [infoArrayobjectAtIndex:0];
NSString *lastVersion = [releaseInfo
objectForKey:@"version"];
if (![lastVersion
isEqualToString:currentVersion]) {
UIAlertView *alert = [[UIAlertViewalloc]
initWithTitle:@"更新"message:@"有新的版本更新,是否前往更新?"delegate:selfcancelButtonTitle:@"关闭"otherButtonTitles:@"更新",nil];
alert.tag =
10000;
[alert show];
}
}
}
//更新地址
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag==10000) {
if (buttonIndex==1) {
NSURL *url = [NSURLURLWithString:@"https://itunes.apple.com/us/app/coband/id1102364142?mt=8"];
下载地址类似:http://itunes.apple.com/app/id1166090758
[[UIApplicationsharedApplication]openURL:url];
}
}
}
相关文章推荐
- AndroidStudio项目导入第三方library
- iOS 10 个实用小技巧(总有你不知道的和你会用到的)
- iOS 开发-单元测试
- iOS 实现时间线列表效果
- ObjectArx 相关博客地址【更新中】
- Android基础知识之frame动画效果
- ObjectArx自定义实体入门(C++)及注意事项
- 【代码笔记】iOS-替换电话号码中间4位为-号
- 【代码笔记】iOS-替换电话号码中间4位为-号
- swift 多线程GCD和延时调用
- AndroidStudio配置SVN以及使用代码管理
- Android基础知识之tween动画效果
- android.app.RemoteServiceException: Bad notification posted from package
- Android判断是否是黑屏
- iOS 处理分割线顶端对齐以及清除tableView多余的下划线,section header 设置无效
- android windowmanager各个属性
- 一个用x86汇编编写的、页式管理、图形化的CS -- App篇
- [公开课]微信公众平台与javaWeb的结合开发
- Android studio - Unable to move Android SDK
- Android 4个常用的工具类