- (void)versionUpdate{
//获得当前发布的版本
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
//耗时的操作---获取某个应用在AppStore上的信息,更改id就行
NSString *string = [NSStringstringWithContentsOfURL:[NSURLURLWithString:@"http://itunes.apple.com/lookup?id=你的APP的id"]
encoding:NSUTF8StringEncodingerror:nil];
NSData *data = [stringdataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingMutableLeaveserror:nil];
//获得上线版本号
NSString *version = [[[dicobjectForKey:@"results"]firstObject]objectForKey:@"version"];
NSString *updateInfo = [[[dicobjectForKey:@"results"]firstObject]objectForKey:@"releaseNotes"];
//获得当前版本
NSString *currentVersion = [[[NSBundlemainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"];
dispatch_async(dispatch_get_main_queue(), ^{
//更新界面
if ( version &&![versionisEqualToString:currentVersion]) {
//有新版本
NSString *message = [NSStringstringWithFormat:@"有新版本发布啦!\n%@",updateInfo];
UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:@"温馨提示"message:messagedelegate:selfcancelButtonTitle:@"忽略"otherButtonTitles:@"前往更新",nil];
//此种写法文字会居中显示,这样视觉效果很不好,下列demo中已经解决将alertview上的文字具有显示 先关文章链接http://blog.csdn.net/bddzzw/article/details/52169261
[alertViewshow];
}else{
//已是最高版本
NSLog(@"已经是最高版本");
}
});
});
}
/*根据被点击按钮的索引处理点击事件--当被按钮被点击了这里做出一个反馈*/
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex ==1) {
NSString *url =@"你的APP在APPstore的网址";//
https://itunes.apple.com/cn/app/qq/id444934666?mt=8 QQ在APPstore的网址
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:url]];
}
}