ios版本自动更新检测

NSString *thisVersion = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleVersion"];

AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];

[mgr.responseSerializer setAcceptableContentTypes: [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil]];

[mgr POST:APPURL parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {

NSArray *array = responseObject[@"results"];

if (array.count != 0) {// 先判断返回的数据是否为空  没上架的时候是空的

NSDictionary *dic = array.firstObject;

NSString *versionStr = [dic objectForKey:@"version"];

NSString *trackViewUrl = [dic objectForKey:@"trackViewUrl"];

NSString *releaseNotes = [dic objectForKey:@"releaseNotes"];

if ([thisVersion compare:versionStr options:NSNumericSearch] == NSOrderedAscending) {

NSString *title = kASLocalizedString(@"Discover a new version");

NSString *cancel = kASLocalizedString(@"Cancel");

NSString *update = kASLocalizedString(@"Update");

[UIAlertView bk_showAlertViewWithTitle:[NSString stringWithFormat:@"%@:%@",title,versionStr] message:releaseNotes cancelButtonTitle:cancel otherButtonTitles:@[update] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {

if (buttonIndex == 1) {

NSURL * url = [NSURL URLWithString:trackViewUrl];                    [[UIApplication sharedApplication] openURL:url];

}

}];

}

}

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

ETLog(@"get version failed");

}];

你可能感兴趣的:(ios版本自动更新检测)