//检测版本更新
- (IBAction)banbengengxin:(id)sender {
NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/lookup?id=APPID"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10];
[request setHTTPMethod:@"POST"];
NSOperationQueue *queue = [NSOperationQueue new];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){
if (data) {
NSDictionary *receiveDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
if ([[receiveDic valueForKey:@"resultCount"] intValue]>0) {
NSString *currentVersion = [[[receiveDic valueForKey:@"results"] objectAtIndex:0] valueForKey:@"version"];
NSString *versionOnPhone = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; //获取项目版本号
if (![versionOnPhone isEqualToString:currentVersion]) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提醒"
message:@"有新的版本更新,是否前往下载。" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *doAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/idAPPID"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }];
[alert addAction:doAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:^{
}];
}
else
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提醒" message:@"已是最新版本" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
}];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:^{
}];
}
}
}
}];
}
卸载点击事件里就行了 上边是判断版本号