检测版本更新

-(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];
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在苹果的 app store 条文中,是不允许新版本提示的, 但是只要不让那些审核员知道有这个功能就可以了。启动的...
    圣斗士皮皮阅读 944评论 0 5
  • 基于良好的用户体验,当在appStroe上线了新的版本时,提醒用户更新”新版本“是必不可少的。 版本更新的...
    ninazhang阅读 1,005评论 5 1
  • //生成属性 当前版本 和 appStore上的版本 @property (nonatomic, strong) ...
    Hope_Man阅读 202评论 0 0
  • 有些App更新新功能并且上线后,会有这样的需求:用户登录后,会提示用户“发现新版本,请更新”,这就需要用户点击确定...
    海耐射手阅读 5,273评论 4 2
  • 01你跟在一起,我从来都不用带脑子 1)没有跟张先生在一起之前,我一个人差不多走遍了整个中国,从来都没有迷过路,不...
    岸荷阅读 651评论 0 3