iOS 版本检测更新方法
2016-06-06 21:31
357 查看
- (void)JudgeAPPVersion
{
NSString *urlStr =@"https://itunes.apple.com/lookup?id=1050852293";
NSURL *url = [NSURLURLWithString:urlStr];
NSURLRequest *req = [NSURLRequestrequestWithURL:url];
[NSURLConnectionconnectionWithRequest:reqdelegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSError *error;
id jsonObject = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingAllowFragmentserror:&error];
NSDictionary *appInfo = (NSDictionary *)jsonObject;
NSArray *infoContent = [appInfo objectForKey:@"results"];
if (infoContent.count <1)
{
return;
}
NSString *version = [[infoContent objectAtIndex:0] objectForKey:@"version"];
NSDictionary *infoDic = [[NSBundlemainBundle]infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
if (![version isEqualToString:currentVersion])
{
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"商店有最新版本了"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
[alert show];
}
}
#pragma mark -- UIAlertViewDelegate method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alertView.cancelButtonIndex)
{
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"itms-apps://itunes.apple.com/cn/app/id1050852293"]];
}
}
请求返回的app信息字段包括:
{
resultCount = 1;
results = (
{
artistId = 开发者 ID;
artistName = 开发者名称;
price = 0;
isGameCenterEnabled = 0;
kind = software;
languageCodesISO2A = (
EN
);
trackCensoredName = 审查名称;
trackContentRating = 评级;
trackId = 应用程序 ID;
trackName = 应用程序名称;
trackViewUrl = 应用程序介绍网址;
userRatingCount = 用户评级;
userRatingCountForCurrentVersion = 1;
version = 版本号;
wrapperType = software;
}
);
}
{
NSString *urlStr =@"https://itunes.apple.com/lookup?id=1050852293";
NSURL *url = [NSURLURLWithString:urlStr];
NSURLRequest *req = [NSURLRequestrequestWithURL:url];
[NSURLConnectionconnectionWithRequest:reqdelegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSError *error;
id jsonObject = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingAllowFragmentserror:&error];
NSDictionary *appInfo = (NSDictionary *)jsonObject;
NSArray *infoContent = [appInfo objectForKey:@"results"];
if (infoContent.count <1)
{
return;
}
NSString *version = [[infoContent objectAtIndex:0] objectForKey:@"version"];
NSDictionary *infoDic = [[NSBundlemainBundle]infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
if (![version isEqualToString:currentVersion])
{
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"商店有最新版本了"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
[alert show];
}
}
#pragma mark -- UIAlertViewDelegate method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alertView.cancelButtonIndex)
{
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"itms-apps://itunes.apple.com/cn/app/id1050852293"]];
}
}
请求返回的app信息字段包括:
{
resultCount = 1;
results = (
{
artistId = 开发者 ID;
artistName = 开发者名称;
price = 0;
isGameCenterEnabled = 0;
kind = software;
languageCodesISO2A = (
EN
);
trackCensoredName = 审查名称;
trackContentRating = 评级;
trackId = 应用程序 ID;
trackName = 应用程序名称;
trackViewUrl = 应用程序介绍网址;
userRatingCount = 用户评级;
userRatingCountForCurrentVersion = 1;
version = 版本号;
wrapperType = software;
}
);
}
相关文章推荐
- iOS Hit-Testing事件响应链
- 【iOS开发】NSString与int和float的相互转换
- 【iOS】打印方法名
- iOS中的触摸事件和手势处理
- 【iOS】设备系统版本
- iOS 如何创建一个线程,要求可以一直工作,不会执行一次就结束
- iOS开发(OC)——根据时间戳转换成不同的显示
- iOS 直播-获取音频(视频)数据
- ios开发中的一些小技巧
- IOS集合视图
- 如何给Label加背景图片
- iOS layout机制相关方法
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet
- 一篇ios开发学习的文章
- iOS中的星星评分功能视图实现
- iOS 获取崩溃信息
- iOS音频播放的几种方式,打开后台模式的音乐播放、使用AVAudioPlayer播放音乐、播放指定的音频文件、注册音频文件
- IOS开发最新的公告关于保存缓存到Documents 发布被拒的解决办法
- iOS开发小技巧--获取自定义的BarButtonItem中的自定义View的方法(customView)
- ios进阶--Autolayout 之第三方框架--Masonry