Skip to content

Instantly share code, notes, and snippets.

@gliubc
Last active September 12, 2019 06:15
Show Gist options
  • Save gliubc/1f7bb69bebf01111512d86c43f67898c to your computer and use it in GitHub Desktop.
Save gliubc/1f7bb69bebf01111512d86c43f67898c to your computer and use it in GitHub Desktop.
- (void)upgrade {
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSString *url = @"Api/PublicApi/getVersion";
NSMutableDictionary *params = [NSMutableDictionary new];
[[[LNNetWorkAPI alloc] initWithUrl:url parameters:params] startWithBlockSuccess:^(__kindof LCBaseRequest *request) {
[SVProgressHUD dismiss];
id json = request.responseJSONObject;
if ([json[@"status"] integerValue] != 1) {
[SVProgressHUD showInfoWithStatus:json[@"msg"]];
return;
}
id data = json[@"data"];
NSString *version = data[@"version"];
NSString *version_desc = data[@"version_desc"];
NSString *version_link = data[@"version_link"];
if ([appVersion compare:version options:NSNumericSearch] == NSOrderedAscending) {
[self confirmWithTitle:nil message:version_desc confirmText:nil confirmOperation:^{
[Util openScheme:version_link];
} cancelText:nil cancelOperation:nil];
}
} failure:^(__kindof LCBaseRequest *request, NSError *error) {
[SVProgressHUD dismiss];
[SVProgressHUD showInfoWithStatus:error.domain];
}];
}
- (void)checkAppStoreVersion {
NSString *checkUrlString =@"https://itunes.apple.com/cn/lookup?id=1458709126";
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:checkUrlString];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"%@ %@", response, responseObject);
NSArray *results = [responseObject arrayForKey:@"results"];
if (results.count) {
NSDictionary *result = results[0];
// 版本号
NSString *version = [result stringForKey:@"version"];
// 应用名称
NSString *trackName = [result stringForKey:@"trackName"];
// 下载地址
NSString *trackViewUrl = [result stringForKey:@"trackViewUrl"];
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *appVersion = infoDictionary[@"CFBundleShortVersionString"];
if ([appVersion compare:version options:NSNumericSearch] == NSOrderedAscending) {
// 更新
[self confirm:@"新的版本可以下载,立即更新?" operation:^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:trackViewUrl]];
}];
}
}
}
}];
[dataTask resume];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment