Commit a2208125e053adae67843e47882973088c21b051

Authored by yanglingyu
1 parent e905b3c0

解决网络不好闪退问题,更改最新alert弹窗

Showing 1 changed file with 24 additions and 24 deletions
CNLiveScioLive/AppDelegate.m
@@ -561,30 +561,30 @@ @@ -561,30 +561,30 @@
561 NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; 561 NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
562 NSString *nowVersion = [infoDict objectForKey:@"CFBundleShortVersionString"]; 562 NSString *nowVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
563 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=%@", uAppId]]; 563 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=%@", uAppId]];
564 - NSString * file = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];  
565 - if (!file) {  
566 - return;  
567 - }  
568 - NSDictionary *dic = [file objectFromJSONString];  
569 - NSDictionary *results = [[dic objectForKey:@"results"] firstObject];  
570 - NSString *newVersion =[results objectForKey:@"version"];  
571 - if([newVersion compare:nowVersion options:NSNumericSearch] == NSOrderedDescending) {  
572 - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"upDate"];  
573 - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CustomStr(@"VersionUpdate")  
574 - message:[results objectForKey:@"releaseNotes"]  
575 - delegate:self  
576 - cancelButtonTitle:CustomStr(@"Cancel")  
577 - otherButtonTitles:CustomStr(@"Update"),nil];  
578 - [alert show];  
579 - return;  
580 - }  
581 -}  
582 -- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{  
583 - if(buttonIndex == 1){  
584 - // 此处加入应用在app store的地址,方便用户去更新,一种实现方式如下:  
585 - NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", uAppId]];  
586 - [[UIApplication sharedApplication] openURL:url];  
587 - } 564 + dispatch_async(dispatch_get_global_queue(0, 0), ^{
  565 + NSString * file = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
  566 + NSDictionary *dic = [file objectFromJSONString];
  567 + if (dic.count<=0) {
  568 + return;
  569 + }
  570 + NSDictionary *results = [[dic objectForKey:@"results"] firstObject];
  571 + NSString *newVersion =[results objectForKey:@"version"];
  572 + if([newVersion compare:nowVersion options:NSNumericSearch] == NSOrderedDescending) {
  573 + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"upDate"];
  574 + dispatch_async(dispatch_get_main_queue(), ^{
  575 + UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:CustomStr(@"VersionUpdate") message:[results objectForKey:@"releaseNotes"] preferredStyle:UIAlertControllerStyleAlert];
  576 + UIAlertAction *action1 = [UIAlertAction actionWithTitle:CustomStr(@"Update") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  577 + NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", uAppId]];
  578 + [[UIApplication sharedApplication] openURL:url];
  579 + }];
  580 + UIAlertAction *action2 = [UIAlertAction actionWithTitle:CustomStr(@"Cancel") style:UIAlertActionStyleCancel handler:nil];
  581 + [alertVC addAction:action2];
  582 + [alertVC addAction:action1];
  583 + [self.window.rootViewController presentViewController:alertVC animated:YES completion:nil];
  584 + });
  585 + }
  586 + });
  587 +
588 } 588 }
589 - (BOOL)shouldAutorotate { 589 - (BOOL)shouldAutorotate {
590 return NO; 590 return NO;