新版本提示

//新版本提示

- (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=你的APPid"] 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"];

扫描二维码关注公众号,回复: 6041939 查看本文章

        //获得当前版本

        _currentVerString = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"];

        dispatch_async(dispatch_get_main_queue(), ^{

           //更新界面

            if (version && ![version isEqualToString:_currentVerString]) {

                //有新版本

                NSString *message = [NSString stringWithFormat:@"有新版本发布 \n%@",updateInfo];

                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleActionSheet];

                UIAlertAction *alert = [UIAlertAction actionWithTitle:@"前往更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

                    /*根据被点击按钮的索引处理点击事件--当被按钮被点击了这里做出一个反馈*/

                    NSString *url = @"你的APPAPPstore的网址";//

                https://itunes.apple.com/cn/app/qq/id444934666?mt=8 QQAPPstore的网址

                    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];

                    

                }];

                UIAlertAction *alertaction = [UIAlertAction actionWithTitle:@"忽略" style:UIAlertActionStyleDefault handler:nil];

                [alertController addAction:alert];

                [alertController addAction:alertaction];

                [self.navigationController presentViewController:alertController animated:YES completion:nil];

            }else{

                [MBProgressHUD showError:@"已是最新版本" toView:self.view];

            }

        });

        

      

    });

}

Demo下载地址:http://download.csdn.NET/detail/bddzzw/9599669


猜你喜欢

转载自blog.csdn.net/qq_31928443/article/details/52787729