Commit 036be141 authored by Sandy's avatar Sandy

版本更新功能

parent df1b41c3
This diff is collapsed.
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "IQUITextFieldView+Additions.h" #import "IQUITextFieldView+Additions.h"
#import "LoginViewModel.h" #import "LoginViewModel.h"
#import "RootNavigationController.h" #import "RootNavigationController.h"
#import "UpdateAlertView.h"
@interface LoginViewController () <UITextFieldDelegate> @interface LoginViewController () <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textFieldName; @property (weak, nonatomic) IBOutlet UITextField *textFieldName;
@property (weak, nonatomic) IBOutlet UITextField *textFieldPWD; @property (weak, nonatomic) IBOutlet UITextField *textFieldPWD;
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
@property (weak, nonatomic) IBOutlet UIImageView *imgBg; @property (weak, nonatomic) IBOutlet UIImageView *imgBg;
@property (weak, nonatomic) IBOutlet UILabel *bottomInfo; @property (weak, nonatomic) IBOutlet UILabel *bottomInfo;
@property (strong, nonatomic) LoginViewModel *viewModel; @property (strong, nonatomic) LoginViewModel *viewModel;
@property (strong, nonatomic) ZJUpdateManager *update;
@end @end
@implementation LoginViewController @implementation LoginViewController
...@@ -51,12 +53,18 @@ ...@@ -51,12 +53,18 @@
} }
- (void)checkUpdate { - (void)checkUpdate {
// WS(weakSelf); [self.update checkOnVC:self complete:^(BOOL isLatest) {
// MBProgressHUD *hud = [MBProgressHUD j_loadingOnView:self.view text:@"检查版本更新中…"]; if (self.textFieldName.text.length > 0 && self.textFieldPWD.text.length >0) {
[self ActionLogin:nil];
}
}];
} }
//登录 //登录
- (IBAction)ActionLogin:(UIButton *)sender { - (IBAction)ActionLogin:(UIButton *)sender {
kCanNotBeNil(self.textFieldName.text, @"请输入用户名!");
kCanNotBeNil(self.textFieldPWD.text, @"请输入密码!");
[MBProgressHUD j_loading:@"登陆中…"]; [MBProgressHUD j_loading:@"登陆中…"];
self.viewModel.loginRequest.principal = self.textFieldName.text; self.viewModel.loginRequest.principal = self.textFieldName.text;
self.viewModel.loginRequest.password = self.textFieldPWD.text; self.viewModel.loginRequest.password = self.textFieldPWD.text;
...@@ -83,5 +91,6 @@ ...@@ -83,5 +91,6 @@
} }
ZJLazy(LoginViewModel, viewModel); ZJLazy(LoginViewModel, viewModel);
ZJLazy(ZJUpdateManager, update);
@end @end
...@@ -11,10 +11,19 @@ ...@@ -11,10 +11,19 @@
#if defined(HDMall_TEST) #if defined(HDMall_TEST)
static NSString *const VERSION_NAME = @"商地开发版"; static NSString *const VERSION_NAME = @"商地开发版";
static NSString *const BASE_IP = @"http://gomoredev.natapp4.cc"; static NSString *const BASE_IP = @"http://dev.gomoretech.com";
//蒲公英appid
static NSString *const PGYER_APPID = @"";
#elif defined(HDMall) #elif defined(HDMall)
static NSString *const VERSION_NAME = @"商地开发版"; static NSString *const VERSION_NAME = @"商地开发版";
static NSString *const BASE_IP = @"http://gomoredev.natapp4.cc"; static NSString *const BASE_IP = @"http://gomoredev.natapp4.cc";
//蒲公英appid
static NSString *const PGYER_APPID = @"";
#elif defined(YI_DI_GANG_TEST)
static NSString *const VERSION_NAME = @"颐堤港测试版";
static NSString *const BASE_IP = @"http://210.12.159.69:8280";
//蒲公英appid
static NSString *const PGYER_APPID = @"";
#else #else
......
//
// UpdateAlertView.h
// RealEstateManagement
//
// Created by Javen on 2017/3/24.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UpdateAlertView : UIView
+ (UpdateAlertView *)alertWithNew:(NSString *)newVersion Content:(NSString *)content isForce:(BOOL)isForce url:(NSString *)url;
+ (instancetype)updateWithVersion:(NSString *)newVersion
webUrl:(NSString *)webUrl
itemUrl:(NSString *)itemUrl
content:(NSString *)content
isForce:(BOOL)isForce
complete:(void (^)(BOOL isLatest))complete;
@end
@interface ZJUpdateManager : NSObject
- (void)checkOnVC:(UIViewController *)vc complete:(void (^)(BOOL isLatest))complete;
@end
//
// UpdateAlertView.m
// RealEstateManagement
//
// Created by Javen on 2017/3/24.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "UpdateAlertView.h"
#import "UpdateResponse.h"
#import "PgyUpdateManager.h"
@interface UpdateAlertView ()
@property (weak, nonatomic) IBOutlet UITextView *textViewContent;
@property (weak, nonatomic) IBOutlet UIButton *btnCancel;
@property (weak, nonatomic) IBOutlet UIButton *btnUpdate;
@property (weak, nonatomic) IBOutlet UILabel *labelNewVersion;
@property (strong, nonatomic) UIView *shadow;
@property (copy, nonatomic) void (^blockUpdate)(void);
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintCancelWidth;
@property (strong, nonatomic) NSString *updateUrl;
@end
@implementation UpdateAlertView
- (void)awakeFromNib {
[super awakeFromNib];
self.shadow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
self.shadow.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.0];
self.cornerRadius = 7;
self.clipsToBounds = YES;
}
+ (UpdateAlertView *)alertWithNew:(NSString *)newVersion Content:(NSString *)content isForce:(BOOL)isForce url:(NSString *)url {
UpdateAlertView *alertView = [UpdateAlertView viewFromNib];
alertView.frame = CGRectMake(0, 0, 280, 220);
alertView.center = kWindow.center;
alertView.transform = CGAffineTransformMakeScale(0.01, 0.01);
alertView.labelNewVersion.text = [NSString stringWithFormat:@"(%@)",newVersion];
//如果没有更新内容就使用默认的内容
if (content != nil) {
alertView.textViewContent.text = content;
}
if (isForce) {
alertView.btnCancel.hidden = YES;
alertView.constraintCancelWidth.constant = 280 - 32;
}
alertView.updateUrl = url;
[alertView alert];
return alertView;
}
+ (instancetype)updateWithVersion:(NSString *)newVersion
webUrl:(NSString *)webUrl
itemUrl:(NSString *)itemUrl
content:(NSString *)content
isForce:(BOOL)isForce
complete:(void (^)(BOOL isLatest))complete {
if ([APP_VERSION compare:newVersion options:NSNumericSearch] != NSOrderedAscending) {
CLog(@"已经是最新版本");
complete(YES);
return nil;
}
complete(NO);
UpdateAlertView *alertView = [UpdateAlertView viewFromNib];
alertView.frame = CGRectMake(0, 0, 280, 220);
alertView.center = kWindow.center;
alertView.transform = CGAffineTransformMakeScale(0.01, 0.01);
alertView.labelNewVersion.text = [NSString stringWithFormat:@"(%@)",newVersion];
//如果没有更新内容就使用默认的内容
if (content != nil) {
alertView.textViewContent.text = content;
}
if (isForce) {
alertView.btnCancel.hidden = YES;
alertView.constraintCancelWidth.constant = 280 - 32;
}
alertView.updateUrl = itemUrl ? itemUrl : webUrl;
[alertView alert];
return alertView;
}
- (void)alert {
[kWindow addSubview:self.shadow];
[kWindow addSubview:self];
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.7
initialSpringVelocity:1.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.shadow.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.3];
self.transform = CGAffineTransformMakeScale(1, 1);
}
completion:nil];
}
- (void)cancel {
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.9
initialSpringVelocity:1.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.transform = CGAffineTransformMakeScale(0.01, 0.01);
self.shadow.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.0];
}
completion:^(BOOL finished) {
[self.shadow removeFromSuperview];
[self removeFromSuperview];
}];
}
#pragma mark - 点击事件
- (IBAction)actionCancel:(id)sender {
[self cancel];
}
- (IBAction)actionUpdate:(id)sender {
[MBProgressHUD j_loading];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[MBProgressHUD j_hideLoadingView];
});
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:self.updateUrl]];
}
@end
@interface ZJUpdateManager ()
@property (nonatomic, strong) UpdateResponse *updateInfo;
@property (assign, nonatomic) UIViewController *superVC;
//@property (strong, nonatomic) MBProgressHUD *hud;
@property (copy, nonatomic) void (^blockComplete)(BOOL);
@end
@implementation ZJUpdateManager
- (void)checkOnVC:(UIViewController *)vc complete:(void (^)(BOOL isLatest))complete {
self.superVC = vc;
self.blockComplete = complete;
WS(weakSelf);
// self.hud = [MBProgressHUD j_loadingOnView:vc.view text:@"检查版本更新中…"];
[ZJHttpManager GET:@"ipapk?type=ipa" parameters:nil complete:^(id responseObject, NSError *error) {
if (kIsResponse) {
weakSelf.updateInfo = [UpdateResponse modelWithDic:responseObject[@"data"]];
[weakSelf pgyerUpdate];
}else{
// [weakSelf.hud hideAnimated:YES];
kFalseHttpTips;
}
}];
}
- (void)pgyerUpdate {
[[PgyUpdateManager sharedPgyManager] startManagerWithAppId:PGYER_APPID];
[[PgyUpdateManager sharedPgyManager] checkUpdateWithDelegete:self selector:@selector(updateMethod:)];
}
- (void)updateMethod:(NSDictionary *)response {
// [self.hud hideAnimated:YES];
NSString *url = response[@"downloadURL"];
[UpdateAlertView updateWithVersion:self.updateInfo.version webUrl:self.updateInfo.url itemUrl:url content:nil isForce:self.updateInfo.forceUpdate complete:self.blockComplete];
}
@end
This diff is collapsed.
@interface UpdateResponse : ZJBaseModel
@property (nonatomic, strong) NSString <Optional> * url;
@property (nonatomic, strong) NSString <Optional> * version;
@property (nonatomic, strong) NSString <Optional> * type;
@property (nonatomic, assign) BOOL forceUpdate;
@property (nonatomic, strong) NSString <Optional> * uuid;
@end
#import "UpdateResponse.h"
@implementation UpdateResponse
@end
...@@ -17,8 +17,9 @@ abstract_target 'hdmall_base' do ...@@ -17,8 +17,9 @@ abstract_target 'hdmall_base' do
pod 'RadioButton' pod 'RadioButton'
pod 'TZImagePickerController', '~> 1.8.4' pod 'TZImagePickerController', '~> 1.8.4'
pod 'DatePickerTextField', '~> 1.0.2' pod 'DatePickerTextField', '~> 1.0.2'
# target 'HDMall' do pod 'PgyUpdate', '~> 1.3'
# end target 'YI_DI_GANG_TEST' do
end
target 'HDMall_TEST' do target 'HDMall_TEST' do
end end
end end
...@@ -22,6 +22,7 @@ PODS: ...@@ -22,6 +22,7 @@ PODS:
- JSONModel (1.7.0) - JSONModel (1.7.0)
- MBProgressHUD (1.0.0) - MBProgressHUD (1.0.0)
- MJRefresh (3.1.12) - MJRefresh (3.1.12)
- PgyUpdate (1.5)
- RadioButton (1.0) - RadioButton (1.0)
- SDWebImage (3.7.6): - SDWebImage (3.7.6):
- SDWebImage/Core (= 3.7.6) - SDWebImage/Core (= 3.7.6)
...@@ -39,6 +40,7 @@ DEPENDENCIES: ...@@ -39,6 +40,7 @@ DEPENDENCIES:
- JSONModel (~> 1.7.0) - JSONModel (~> 1.7.0)
- MBProgressHUD (~> 1.0.0) - MBProgressHUD (~> 1.0.0)
- MJRefresh (~> 3.1.2) - MJRefresh (~> 3.1.2)
- PgyUpdate (~> 1.3)
- RadioButton - RadioButton
- SDWebImage (~> 3.7.4) - SDWebImage (~> 3.7.4)
- TZImagePickerController (~> 1.8.4) - TZImagePickerController (~> 1.8.4)
...@@ -54,11 +56,12 @@ SPEC CHECKSUMS: ...@@ -54,11 +56,12 @@ SPEC CHECKSUMS:
JSONModel: 840bc0fcffb24b8454d2c026bf26fea454b8e98d JSONModel: 840bc0fcffb24b8454d2c026bf26fea454b8e98d
MBProgressHUD: 4890f671c94e8a0f3cf959aa731e9de2f036d71a MBProgressHUD: 4890f671c94e8a0f3cf959aa731e9de2f036d71a
MJRefresh: b96cdb21c4aa75a7b07654311ab2f315c497e806 MJRefresh: b96cdb21c4aa75a7b07654311ab2f315c497e806
PgyUpdate: bad71685b91bba4aa520b7fe29356a476700fdf2
RadioButton: 7ef053baf6ff0e7f9e777016c28e9ba4e330edba RadioButton: 7ef053baf6ff0e7f9e777016c28e9ba4e330edba
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9 SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
TZImagePickerController: 612c79b572efd0363c7a966daad7a974c2d6b458 TZImagePickerController: 612c79b572efd0363c7a966daad7a974c2d6b458
UMengAnalytics-NO-IDFA: 16666e32edce5be44ae5b14aaaa7f3582e09d6ab UMengAnalytics-NO-IDFA: 16666e32edce5be44ae5b14aaaa7f3582e09d6ab
PODFILE CHECKSUM: c1276e98223591bc2e638bb9b75d4116e596b88a PODFILE CHECKSUM: 83258bebe74e593eb0e5038dcb7ae3bb688b19d1
COCOAPODS: 1.2.1 COCOAPODS: 1.2.1
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