Commit 3a240f77 authored by admin's avatar admin

添加“检查版本”

parent 1a9e7d2b
...@@ -26,12 +26,9 @@ ...@@ -26,12 +26,9 @@
LoginViewController *loginVC = [[LoginViewController alloc] init]; LoginViewController *loginVC = [[LoginViewController alloc] init];
self.window.rootViewController = loginVC; self.window.rootViewController = loginVC;
return YES; return YES;
} }
- (void)applicationWillResignActive:(UIApplication *)application { - (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
// url // url
#define kRedStarURL @"http://218.244.151.129:7580/" #define kRedStarURL @"http://218.244.151.129:7580/"
// 检查更新
#define kCheckUpdateURL @"redstar-server/rest/ipapk?type=ipa"
// login // login
#define kLoginURL @"redstar-server/rest/user/login/" #define kLoginURL @"redstar-server/rest/user/login/"
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#define kUsernameTableViewCell @"usernameTableViewCell" #define kUsernameTableViewCell @"usernameTableViewCell"
@interface LoginViewController () <CustomDropMenuDelegate, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource, UITabBarControllerDelegate> { @interface LoginViewController () <CustomDropMenuDelegate, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource, UITabBarControllerDelegate, UIAlertViewDelegate> {
BOOL isOpened; // 判断存取本地的tableView是否打开 BOOL isOpened; // 判断存取本地的tableView是否打开
} }
@property (nonatomic, strong) LoginView *loginView; @property (nonatomic, strong) LoginView *loginView;
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
@property (nonatomic, strong) CustomDropMenuView *menu; @property (nonatomic, strong) CustomDropMenuView *menu;
@property (nonatomic, strong) RootTabBarController *rootTBC; @property (nonatomic, strong) RootTabBarController *rootTBC;
@property (nonatomic, strong) NSString *jumpURL;
@end @end
@implementation LoginViewController @implementation LoginViewController
...@@ -39,6 +39,9 @@ ...@@ -39,6 +39,9 @@
- (void)viewDidLoad - (void)viewDidLoad
{ {
[super viewDidLoad]; [super viewDidLoad];
[self getVersion];
isOpened = NO; isOpened = NO;
[self addAllClick]; [self addAllClick];
...@@ -64,6 +67,47 @@ ...@@ -64,6 +67,47 @@
} }
#pragma mark - Private Methods #pragma mark - Private Methods
// 获取版本
- (void)getVersion
{
HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:[NSString stringWithFormat:@"%@%@", kRedStarURL, kCheckUpdateURL]];
[httpCilent checkAndUpdateCurrentVersionWithCompletion:^(id response, NSError *error) {
if (response[@"data"] == nil && response[@"data"] == NULL && response[@"data"] == [NSNull null]) {
NSDictionary *dict = response[@"data"];
NSString *newVersion = [NSString stringWithFormat:@"%@", dict[@"version"]];
self.jumpURL = [NSString stringWithFormat:@"%@", dict[@"url"]];
[self checkAppUpdate:newVersion];
} else {
return;
}
}];
}
- (void)checkAppUpdate:(NSString *)newVersion
{
// 获取当前版本
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [NSString stringWithFormat:@"%@",infoDic[@"CFBundleShortVersionString"]];
NSLog(@"当前版本是:%@", currentVersion);
if (![currentVersion isEqualToString:newVersion]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示!" message:[NSString stringWithFormat:@"发现新版本:%@", newVersion] delegate:self cancelButtonTitle:@"稍后再说" otherButtonTitles:@"前往更新", nil];
[alert show];
alert.tag = 3058284;
}
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1 && alertView.tag == 3058284) {
NSString *url = self.jumpURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
}
- (void)requestLogin - (void)requestLogin
{ {
......
...@@ -22,6 +22,9 @@ typedef void (^completionBlock) (id response, NSError *error); ...@@ -22,6 +22,9 @@ typedef void (^completionBlock) (id response, NSError *error);
// 登陆 // 登陆
- (void)loginWithUsername:(NSString *)username password:(NSString *)password completion:(completionBlock)completion; - (void)loginWithUsername:(NSString *)username password:(NSString *)password completion:(completionBlock)completion;
// 检查更新版本
- (void)checkAndUpdateCurrentVersionWithCompletion:(completionBlock)completion;
// 获取问题列表 // 获取问题列表
- (void)getQuestionListWithParameters:(id)parameters completion:(completionBlock)completion; - (void)getQuestionListWithParameters:(id)parameters completion:(completionBlock)completion;
......
...@@ -105,6 +105,15 @@ ...@@ -105,6 +105,15 @@
}]; }];
} }
- (void)checkAndUpdateCurrentVersionWithCompletion:(completionBlock)completion
{
[self getParameters:nil completion:^(id response, NSError *error) {
if (completion) {
completion (response, error);
}
}];
}
// 获取问题列表 // 获取问题列表
- (void)getQuestionListWithParameters:(id)parameters completion:(completionBlock)completion - (void)getQuestionListWithParameters:(id)parameters completion:(completionBlock)completion
{ {
......
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