iOS版本更新提示

检测线上是否有新版本发布

- (void)versionUpdate{
 
 //获得当前发布的版本
 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
  //耗时的操作---获取某个应用在AppStore上的信息,更改id就行
  NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://itunes.apple.com/lookup?id=你的APP的id"] encoding:NSUTF8StringEncoding error:nil];
  NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
  NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
  //获得上线版本号
  NSString *version = [[[dic objectForKey:@"results"]firstObject]objectForKey:@"version"];
  
  NSString *updateInfo = [[[dic objectForKey:@"results"]firstObject]objectForKey:@"releaseNotes"];
  
  //获得当前版本
  NSString *currentVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"];
  
  dispatch_async(dispatch_get_main_queue(), ^{
   //更新界面
   
   if ( version &&![version isEqualToString:currentVersion]) {
    //有新版本
    NSString *message = [NSString stringWithFormat:@"有新版本发布啦!\n%@",updateInfo];
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:message delegate:self cancelButtonTitle:@"忽略"otherButtonTitles:@"前往更新",nil];
    //此种写法文字会居中显示,这样视觉效果很不好,下列demo中已经解决将alertview上的文字具有显示 先关文章链接http://blog.csdn.net/bddzzw/article/details/52169261
    [alertView show];
   }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的网址
  [[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];
 }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 用到版本更新,首先现在网络上搜了搜发现没有满意的,于是参考一个 重写了一下,支持1.1.1.1.2这种的 版本判断...
    谁在呼叫贱队阅读 1,099评论 0 0
  • 苹果审核中如果发现项目中有版本更新提示,将禁止上架,那么我们可以让后台传一个字段,上架前后修改一下即可,或者通过下...
    fulen阅读 3,917评论 2 3
  • 项目需求:由于公司项目是做离线地图的,老板希望有版本更新时用户能及时更新,所以要求app第一次检测到版本更新时记录...
    字节码阅读 996评论 3 2
  • 最近项目中用到了这个,所以简要谈一下,之前一直没负责过这块,顺便自己mark一下。 需求:有新版本提示用户进行...
    捏捏你的脸阅读 1,166评论 1 4
  • 目录 QuickTime PlayeriOS通过iTunes search检测版本更新,并提示用户更新!How t...
    绍清_shao阅读 1,513评论 0 1