1、效果图
2、关键点
请求 http://itunes.apple.com/lookup?id=968615456
,就会返回关于这个应用的详细内容的JSON数据,后面就简单了吧
我的应用返回的JSON数据(已经格式化):
1 | { |
3、检查更新Demo
检查更新
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15[AFNetworkingUtils getRequestWithUrl:@"http://itunes.apple.com/lookup?id=968615456" afterExecute:^(NSDictionary *resultDic) {
float version =[[[[resultDic objectForKey:@"results"] objectAtIndex:0] valueForKey:@"version"] floatValue];
NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];
float currentVersion = [[infoDic valueForKey:@"CFBundleShortVersionString"] floatValue];
if(version>currentVersion){
NSString *alertTitle=[@"桂林理工大学-校园通v" stringByAppendingString:[NSString stringWithFormat:@"%0.1f",version]];
NSString *alertMsg=@"是否要更新?";
//NSString *alertMsg = [[[resultDic objectForKey:@"results"] objectAtIndex:0] valueForKey:@"releaseNotes"]
UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:alertTitle message:alertMsg delegate:self cancelButtonTitle:@"稍后更新" otherButtonTitles:@"立即更新", nil];
[alertView show];
}
} onError:^{
}];跳到AppStore更新
1
2NSString *url = @"https://itunes.apple.com/us/app/gui-lin-li-gong-da-xue-xiao/id968615456?mt=8&uo=4";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
4、自定义成一个工具
- 使用时调用这个方法就行
1 |
|
- 网络请求方法-(void)checkUpdateWithAppID:(NSString *)appID success:(void (^)(NSDictionary *resultDic , BOOL isNewVersion , NSString * newVersion))success failure:(void (^)(NSError *error))failure
1 |
|
- 提醒方法- (void)showUpdateView:(NSString *)newVersion
** 注:这个是iOS8以后的UIAlertController **
1 | - (void)showUpdateView:(NSString *)newVersion |
5、检查增强
- 服务器版本跟本地版本可以随意,比如服务器1.4.1 ,本地1.4,也能检查了。
1 | NSString * serverVersion =[[[resultDic objectForKey:@"results"] objectAtIndex:0] valueForKey:@"version"]; |
> 注:本文首发于 [iHTCboy's blog](http://iHTCboy.com),如若转载,请注来源