通过下载链接检测版本更新

-(void)GetUpdate

    NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; 

    NSString *nowVersion = [infoDict objectForKey:@"CFBundleVersion"]; 


    NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=***"]; 

    NSString * file =  [NSString stringWithContentsOfURL:url]; 

    NSLog(file); 

    NSRange substr = [file rangeOfString:@"\"version\":\""]; 

    NSRange substr2 =[file rangeOfString:@"\"" options:NULL range:NSRange{substr.location+substr.length,10}]; 

    NSRange range = {substr.location+substr.length,substr2.location-substr.location-substr.length}; 

    NSString *newVersion =[file substringWithRange:range]; 

    if([nowVersion isEqualToString:newVersion]==NO) 

    { 

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"版本有更新" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"更新", nil]; 

        [alert show];

    } 


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 

  if(buttonIndex==1) 

  { 

      NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/us/app/qun-xiang-dao/id***?ls=1&mt=8"]; 

      [[UIApplication sharedApplication]openURL:url]; 

  } 

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容