检测版本更新

-(void)getVersion
{
    if (self.oldTime != self.showTime) {
        
        NSString *url = @"http://itunes.apple.com/CN/lookup?bundleId=com.dyrt.rtjf";
        NSURL *APPUrl = [NSURL URLWithString:url];
        NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
        NSURLRequest *request = [NSURLRequest requestWithURL:APPUrl];
        NSURLSessionDataTask *task =  [session  dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSLog(@"APP商店信息-------%@",dic);
            int resultCount = [[dic objectForKey:@"resultCount"] intValue];
            if(resultCount > 0){
                NSArray *infoArray = [dic objectForKey:@"results"];
                NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
                NSString *appStoreVersion = [releaseInfo objectForKey:@"version"];
                if(infoArray && releaseInfo && appStoreVersion)
                {
                    NSString *note = [releaseInfo objectForKey:@"releaseNotes"];
                    
                    NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
                    NSString* localVerson = [infoDict objectForKey:@"CFBundleShortVersionString"];
                    //                NSString *localVerson = [Uilities sharedInstance].getCurrentAppVersion;
                    
                    if ([appStoreVersion compare:localVerson options:NSNumericSearch] == NSOrderedDescending){
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"有新版本了!赶快更新吧,第一时间体验新功能!"
                                                                         message:note//更新内容
                                                                        delegate:self
                                                               cancelButtonTitle:@"稍后"
                                                               otherButtonTitles:@"更新",nil];
                            
                            [av show];
                        });
                    }
                }
            }
        }];
        [task resume];

    }
   }

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        NSString *urlstr = @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=1128601328";
        NSURL *url = [NSURL URLWithString:urlstr];
        [[UIApplication sharedApplication] openURL:url];
    }
}

推荐阅读更多精彩内容