Commit 46151da3 authored by Achilles's avatar Achilles

版本检查 。

parent c4916672
......@@ -15,6 +15,7 @@
#import "ICRAppMacro.h"
#import "AppDelegate.h"
#import "GEToast.h"
#import "VankeVersionAPI.h"
#import "VankeCommonModel.h"
#define TAG_ACTION_SHEET_EXIT 0
......@@ -23,6 +24,7 @@
@property (strong, nonatomic) IBTTableViewInfo *m_tableViewInfo;
@property (weak, nonatomic) ICRSystemHeaderView *m_tableHeader;
@property (strong, nonatomic) NSString *upgradeUrl;
@end
@implementation ICRSystemViewController
......@@ -190,8 +192,7 @@ ON_DID_APPEAR( signal )
}
- (void) onCheckNewVersion: (__unused id)sender {
// TODO
[GEToast showWithText:@"当前已经是最新版本了" bottomOffset:45.0f duration:1.0f];
[self checkNewVersion];
}
-(void) confirmToLogout {
......@@ -232,4 +233,69 @@ ON_DID_APPEAR( signal )
}
}
-(void) checkNewVersion {
[VankeVersionAPI cancel];
VankeVersionAPI *api = [VankeVersionAPI api];
@weakify(api);
@weakify(self);
api.whenSucceed = ^{
@normalize(api);
@normalize(self);
if (api.succeed) {
[GEToast hideProgress];
if (nil == api.serverResp) {
api.failed = YES;
} else {
VersionResponse *resp = (VersionResponse*) api.serverResp;
[self performSelector:@selector(tryToUpdate:) withObject:resp];
}
}
};
api.whenFailed = ^{
[GEToast hideProgress];
[GEToast showWithText:@"当前已经是最新版本了" bottomOffset:45.0f duration:1.0f];
};
[GEToast showProgress:self.view];
[api send];
}
-(void) tryToUpdate: (VersionResponse*) resp {
VersionNumber *newVersion = [resp newVersion];
if (nil == newVersion) {
[GEToast showWithText:@"当前已经是最新版本了" bottomOffset:45.0f duration:1.0f];
} else {
INFO(@"发现新版本: %@", [newVersion toString]);
self.upgradeUrl = resp.data.url;
NSString *msg = [NSString stringWithFormat:@"发现新版本: %@, 请前往下载!", [newVersion toString]];
if ([resp isForceUpdate]) {
UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"新版本告知" message: msg delegate:self cancelButtonTitle:nil otherButtonTitles: @"去下载", nil];
alertV.tag = 1001;
[alertV show];
} else {
UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"新版本告知" message: msg delegate:self cancelButtonTitle:@"下次再说"otherButtonTitles: @"去下载", nil];
alertV.tag = 1002;
[alertV show];
}
}
}
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == 1001) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.upgradeUrl]];
} else if (alertView.tag == 1002) {
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.upgradeUrl]];
} else {
// TODO
}
}
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment