Commit 3cff0867 authored by IOS-张 博's avatar IOS-张 博

修改token限制,并修改保存图片逻辑

parent 959db4c5
...@@ -46,38 +46,18 @@ ...@@ -46,38 +46,18 @@
//1.创建Window //1.创建Window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor]; self.window.backgroundColor = [UIColor whiteColor];
QGDefaultLaunchViewController * defaultVC = [[QGDefaultLaunchViewController alloc] init]; [self refreshTokenFinishWithOptions:launchOptions];
self.window.rootViewController = defaultVC;
@weakify(self);
defaultVC.continueBlock = ^{
@strongify(self);
NSLog(@"______自由的飞翔");
[self refreshTokenFinishWithOptions:launchOptions];
};
//2.设置Window为主窗口并显示出来 //2.设置Window为主窗口并显示出来
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
/*
//不管成功失败,继续回调
@weakify(self);
[[SystemManager shareInstance] refreshTokenWithResult:^(BOOL isSuccess, NSString *token) {
@strongify(self);
NSLog(@"[Message]----- Token:%@",token);
[self refreshTokenFinishWithOptions:launchOptions];
}];
*/
return YES; return YES;
} }
/// 刷新token接口是最大的接口,优先请求 /// 刷新token接口是最大的接口,优先请求
- (void)refreshTokenFinishWithOptions:(NSDictionary *)launchOptions - (void)refreshTokenFinishWithOptions:(NSDictionary *)launchOptions
{ {
//刷新token
[[SystemManager shareInstance] refreshTokenWithSuccess:nil failure:nil];
QGRootTabbarController * tabbar = [[QGRootTabbarController alloc] init]; QGRootTabbarController * tabbar = [[QGRootTabbarController alloc] init];
self.window.rootViewController = tabbar; self.window.rootViewController = tabbar;
//友盟统计 //友盟统计
......
...@@ -81,32 +81,32 @@ ...@@ -81,32 +81,32 @@
[QGHUDManager showHud:nil]; [QGHUDManager showHud:nil];
} }
@weakify(self); @weakify(self);
[[SystemManager shareInstance] refreshTokenWithTimeoutInterval:timeoutInterval Success:^(BOOL isSuccess, NSString *token) { // [[SystemManager shareInstance] refreshTokenWithTimeoutInterval:timeoutInterval Success:^(BOOL isSuccess, NSString *token) {
@strongify(self); // @strongify(self);
//隐藏loading // //隐藏loading
if (self.requestCount > 1) { // if (self.requestCount > 1) {
[QGHUDManager hideHud]; // [QGHUDManager hideHud];
} // }
//请求成功,并且是0000 // //请求成功,并且是0000
//皆大欢喜,直接执行成功回调,正常显示页面 // //皆大欢喜,直接执行成功回调,正常显示页面
if (isSuccess) { // if (isSuccess) {
if (self.continueBlock) { // if (self.continueBlock) {
self.continueBlock(); // self.continueBlock();
} // }
} // }
else // else
{ // {
[self refreshTokenRequestFail]; // [self refreshTokenRequestFail];
} // }
} failure:^(NSError *error) { // } failure:^(NSError *error) {
@strongify(self); // @strongify(self);
//隐藏loading // //隐藏loading
if (self.requestCount > 1) { // if (self.requestCount > 1) {
[QGHUDManager hideHud]; // [QGHUDManager hideHud];
} // }
//
[self refreshTokenRequestFail]; // [self refreshTokenRequestFail];
}]; // }];
} }
///没有获取到token ///没有获取到token
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#import "SystemManager.h" #import "SystemManager.h"
#import "QGBasicUITool.h" #import "QGBasicUITool.h"
#import "QGAlertView.h" #import "QGAlertView.h"
#import "QGActionSheetView.h"
#import <Photos/Photos.h> #import <Photos/Photos.h>
@interface MagnifyImageView ()<UIScrollViewDelegate> @interface MagnifyImageView ()<UIScrollViewDelegate>
...@@ -65,24 +66,16 @@ ...@@ -65,24 +66,16 @@
self.scrollView.clipsToBounds = NO; self.scrollView.clipsToBounds = NO;
[self addSubview:self.scrollView]; [self addSubview:self.scrollView];
//下载图片按钮
UIButton * saveImgButton = [UIButton creatButtonWithSuperView:self title:nil titleFont:nil textColor:nil];
[saveImgButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.inset(10);
make.size.mas_equalTo(CGSizeMake(50, 50));
make.bottom.inset(70);
}];
saveImgButton.backgroundColor = [UIColor redColor];
[saveImgButton addTarget:self action:@selector(saveImgButtonClick) forControlEvents:UIControlEventTouchUpInside];
// add image views // add image views
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
for (NSInteger i = 0; i < images.count; i++) { for (NSInteger i = 0; i < images.count; i++) {
DMOScalingImageView *scalingImageView = [[DMOScalingImageView alloc] initWithFrame:CGRectMake(ScreenWidth * i, 0, ScreenWidth, ScreenHeight)]; DMOScalingImageView *scalingImageView = [[DMOScalingImageView alloc] initWithFrame:CGRectMake(ScreenWidth * i, 0, ScreenWidth, ScreenHeight)];
scalingImageView.imageURL = [NSURL URLWithString:images[i]]; scalingImageView.imageURL = [NSURL URLWithString:images[i]];
@weakify(self);
scalingImageView.longPressHandler = ^(UIImage *image) { scalingImageView.longPressHandler = ^(UIImage *image) {
@strongify(self);
[self showSheetView];
}; };
scalingImageView.tapGestureHandler = ^(DMOScalingImageView *scalingImageView) { scalingImageView.tapGestureHandler = ^(DMOScalingImageView *scalingImageView) {
[weakSelf tapGestureHandlerWithScalingImageView:scalingImageView]; [weakSelf tapGestureHandlerWithScalingImageView:scalingImageView];
...@@ -191,6 +184,20 @@ ...@@ -191,6 +184,20 @@
} }
///显示图片保存选项
- (void)showSheetView
{
@weakify(self);
QGActionSheetView * sheetView = [[QGActionSheetView alloc] initWithTitle:nil options:@[@[@"保存图片"],@[@"取消"]] clickBlock:^(NSInteger index) {
@strongify(self);
if (index == 1) {
[self saveImgButtonClick];
}
}];
[sheetView showInView:nil];
}
/// 保存图片到本地 /// 保存图片到本地
- (void)saveImgButtonClick - (void)saveImgButtonClick
{ {
......
...@@ -34,12 +34,11 @@ ...@@ -34,12 +34,11 @@
/// 刷新token接口,内部判断登录状态下每日调用一次接口 /// 刷新token接口,内部判断登录状态下每日调用一次接口
/// @param timeoutInterval 超时时间,外部设置
/// @param successBlock 成功回调 /// @param successBlock 成功回调
/// isSuccess = YES 请求成功并且业务处理成功,token可用 场景:当日已经刷新过 | 首次刷新成功时调用(状态码为0000) /// isSuccess = YES 请求成功并且业务处理成功,token可用 场景:当日已经刷新过 | 首次刷新成功时调用(状态码为0000)
/// isSuccess = NO 请求成功业务处理失败,token不可用 场景:状态码非0000 /// isSuccess = NO 请求成功业务处理失败,token不可用 场景:状态码非0000
/// @param failureBlock 网络请求失败回调 /// @param failureBlock 网络请求失败回调
- (void)refreshTokenWithTimeoutInterval:(NSTimeInterval)timeoutInterval Success:(void(^)(BOOL isSuccess, NSString * token))successBlock failure:(void(^)(NSError * error))failureBlock; - (void)refreshTokenWithSuccess:(void(^)(BOOL isSuccess, NSString * token))successBlock failure:(void(^)(NSError * error))failureBlock;
/// 检查升级 /// 检查升级
......
...@@ -22,8 +22,7 @@ ...@@ -22,8 +22,7 @@
#import "DeveloperFileManager.h" #import "DeveloperFileManager.h"
#import "QGAnalyticsService.h" #import "QGAnalyticsService.h"
///刷新token的日期
#define VCCRefreshTokenDate @"VCCRefreshTokenDate"
///上次推荐更新提示的日期 ///上次推荐更新提示的日期
#define VCCLastUpdateHintDate @"VCCLastUpdateHintDate" #define VCCLastUpdateHintDate @"VCCLastUpdateHintDate"
...@@ -45,21 +44,11 @@ static SystemManager * shareManager = nil; ...@@ -45,21 +44,11 @@ static SystemManager * shareManager = nil;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
shareManager = [[SystemManager alloc]init]; shareManager = [[SystemManager alloc]init];
[[NSNotificationCenter defaultCenter] addObserver:shareManager selector:@selector(reloadRefreshTokenDate) name:ModelCenterUserLoginNotification object:nil];
}); });
return shareManager; return shareManager;
} }
///登录后,记录今天已经刷新过
- (void)reloadRefreshTokenDate
{
NSDate * todayDate = [NSDate date];
//每日一次
NSString * todayStr = [[QGCalendarManager shareInstance] getStringFromDate:todayDate formatter:@"yyyyMMdd"];
//记录日期
[[QGCacheManager shareCacheManager] setUserConfigInfoValue:todayStr forKey:VCCRefreshTokenDate];
}
...@@ -67,13 +56,12 @@ static SystemManager * shareManager = nil; ...@@ -67,13 +56,12 @@ static SystemManager * shareManager = nil;
#pragma mark - /*************************/ #pragma mark - /*************************/
/// 刷新token接口,内部判断登录状态下每日调用一次接口 /// 刷新token接口,启动时调用
/// @param timeoutInterval 超时时间,外部设置
/// @param successBlock 成功回调 /// @param successBlock 成功回调
/// isSuccess = YES 请求成功并且业务处理成功,token可用 场景:当日已经刷新过 | 首次刷新成功时调用(状态码为0000) /// isSuccess = YES 请求成功并且业务处理成功,token可用 场景:刷新成功时调用(状态码为0000)
/// isSuccess = NO 请求成功业务处理失败,token不可用 场景:状态码非0000 /// isSuccess = NO 请求成功业务处理失败,token不可用 场景:状态码非0000
/// @param failureBlock 网络请求失败回调 /// @param failureBlock 网络请求失败回调
- (void)refreshTokenWithTimeoutInterval:(NSTimeInterval)timeoutInterval Success:(void(^)(BOOL isSuccess, NSString * token))successBlock failure:(void(^)(NSError * error))failureBlock - (void)refreshTokenWithSuccess:(void(^)(BOOL isSuccess, NSString * token))successBlock failure:(void(^)(NSError * error))failureBlock
{ {
//未登陆直接返回 //未登陆直接返回
if (![QGUserInfo sharedUserInfo].isLogin) { if (![QGUserInfo sharedUserInfo].isLogin) {
...@@ -83,26 +71,12 @@ static SystemManager * shareManager = nil; ...@@ -83,26 +71,12 @@ static SystemManager * shareManager = nil;
return; return;
} }
//首先检测今日是否已经触发过
NSDate * todayDate = [NSDate date];
//每日一次
NSString * todayStr = [[QGCalendarManager shareInstance] getStringFromDate:todayDate formatter:@"yyyyMMdd"];
NSString * refreshDate = [[QGCacheManager shareCacheManager] userConfigInfoValueForKey:VCCRefreshTokenDate];
//本地有存储数据,并且日期与今天一致,说明今天已经请求过了,今日不再请求
if (![NSString isEmpty:refreshDate] && [refreshDate isEqualToString:todayStr]) {
//成功回调
if (successBlock) {
successBlock(YES, [QGUserInfo sharedUserInfo].token);
}
return;
}
//进入请求流程 //进入请求流程
NSString * urlString = [QGLoginRequestApi urlWithQGLoginRequestServerMethod:QGLoginRequestServerMethodAuthRefreshToken]; NSString * urlString = [QGLoginRequestApi urlWithQGLoginRequestServerMethod:QGLoginRequestServerMethodAuthRefreshToken];
NSMutableDictionary * headerParam = [NSMutableDictionary dictionary]; NSMutableDictionary * headerParam = [NSMutableDictionary dictionary];
[headerParam setObject:[QGUserInfo sharedUserInfo].vccRefreshToken forKey:@"vcc-refresh-token"]; [headerParam setObject:[QGUserInfo sharedUserInfo].vccRefreshToken forKey:@"vcc-refresh-token"];
[[QGTalosNetwork shareManager] sendBaseRequestWithUrlString:urlString headers:headerParam timeoutInterval:timeoutInterval opt:BASE_OPT_GET parameters:nil success:^(id _Nonnull responseObject) { [[QGTalosNetwork shareManager] GET:urlString headers:headerParam parameters:nil success:^(id _Nonnull responseObject) {
if ([QGBaseNetwork checkBusinessCodeAndCodeWithResponseObjectObject:responseObject]) { if ([QGBaseNetwork checkBusinessCodeAndCodeWithResponseObjectObject:responseObject]) {
NSDictionary * dataDic = responseObject[@"data"]; NSDictionary * dataDic = responseObject[@"data"];
[QGUserInfo sharedUserInfo].token = dataDic[@"token"]; [QGUserInfo sharedUserInfo].token = dataDic[@"token"];
...@@ -111,8 +85,7 @@ static SystemManager * shareManager = nil; ...@@ -111,8 +85,7 @@ static SystemManager * shareManager = nil;
[QGUserInfo sharedUserInfo].userId = [NSString stringWithFormat:@"%@", dataDic[@"userId"]];; [QGUserInfo sharedUserInfo].userId = [NSString stringWithFormat:@"%@", dataDic[@"userId"]];;
[QGUserInfo sharedUserInfo].userName = dataDic[@"phoneNo"]; [QGUserInfo sharedUserInfo].userName = dataDic[@"phoneNo"];
//记录日期
[[QGCacheManager shareCacheManager] setUserConfigInfoValue:todayStr forKey:VCCRefreshTokenDate];
[[NSNotificationCenter defaultCenter] postNotificationName:ModelCenterUserRefreshToken object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:ModelCenterUserRefreshToken object:nil];
//添加刷新token成功 //添加刷新token成功
...@@ -134,6 +107,8 @@ static SystemManager * shareManager = nil; ...@@ -134,6 +107,8 @@ static SystemManager * shareManager = nil;
if (successBlock) { if (successBlock) {
successBlock(NO, nil); successBlock(NO, nil);
} }
[QGUserInfo logOut];
} }
} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) { } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
//添加刷新token失败埋点 //添加刷新token失败埋点
...@@ -145,97 +120,7 @@ static SystemManager * shareManager = nil; ...@@ -145,97 +120,7 @@ static SystemManager * shareManager = nil;
failureBlock(error); failureBlock(error);
} }
}]; }];
}
/*
/// 刷新token接口,登录状态下每日一次 限时1s
/// @param resultBlock 结果回调
/// isSuccess = YES 处理成功,token可用 场景:当日已经刷新过 | 首次刷新成功时调用
/// isSuccess = NO 处理失败,清除登录状态 场景:请求时长超过1s | 请求失败 | 未登陆
- (void)refreshTokenWithResult:(void(^)(BOOL isSuccess, NSString * token))resultBlock
{
//已登录
if ([QGUserInfo sharedUserInfo].isLogin) {
//首先检测今日是否已经触发过
//遗留问题:应用杀死时,didFinishLaunchingWithOptions会被再次调用
NSDate * todayDate = [NSDate date];
//每日一次
NSString * todayStr = [[QGCalendarManager shareInstance] getStringFromDate:todayDate formatter:@"yyyyMMdd"];
NSString * refreshDate = [[QGCacheManager shareCacheManager] userConfigInfoValueForKey:VCCRefreshTokenDate];
//本地有存储数据,并且日期与今天一致,说明今天已经请求过了,今日不再请求
if (![NSString isEmpty:refreshDate] && [refreshDate isEqualToString:todayStr]) {
//成功回调
if (resultBlock) {
resultBlock(YES, [QGUserInfo sharedUserInfo].token);
}
return;
}
//进入请求流程
NSString * urlString = [QGLoginRequestApi urlWithQGLoginRequestServerMethod:QGLoginRequestServerMethodAuthRefreshToken];
NSMutableDictionary * headerParam = [NSMutableDictionary dictionary];
[headerParam setObject:[QGUserInfo sharedUserInfo].vccRefreshToken forKey:@"vcc-refresh-token"];
[[QGTalosNetwork shareManager] sendBaseRequestWithUrlString:urlString headers:headerParam timeoutInterval:5 opt:BASE_OPT_GET parameters:nil success:^(id _Nonnull responseObject) {
if ([QGBaseNetwork checkBusinessCodeAndCodeWithResponseObjectObject:responseObject]) {
NSDictionary * dataDic = responseObject[@"data"];
[QGUserInfo sharedUserInfo].token = dataDic[@"token"];
[QGUserInfo sharedUserInfo].vccRefreshToken = dataDic[@"vccRefreshToken"];
[QGUserInfo sharedUserInfo].uuid = dataDic[@"uuid"];
[QGUserInfo sharedUserInfo].userName = dataDic[@"phoneNo"];
//成功回调
if (resultBlock) {
resultBlock(YES, [QGUserInfo sharedUserInfo].token);
}
//记录日期
[[QGCacheManager shareCacheManager] setUserConfigInfoValue:todayStr forKey:VCCRefreshTokenDate];
[[NSNotificationCenter defaultCenter] postNotificationName:ModelCenterUserRefreshToken object:nil];
//添加刷新token成功
QGAppBusinessStateEvent * event = [QGAppBusinessStateEvent abseEventWithPage:@"APP启动" action:@"刷新token" value:@"success" code:nil desc:nil phone:[QGUserInfo sharedUserInfo].userName];
[QGAnalyticsService analyticsTrackWithEvent:event];
}
else
{
//添加刷新token失败埋点
QGAppBusinessStateEvent * event = [QGAppBusinessStateEvent abseEventWithPage:@"APP启动" action:@"刷新token" value:@"failed" code:responseObject[@"code"] desc:responseObject[@"msg"] phone:[QGUserInfo sharedUserInfo].userName];
[QGAnalyticsService analyticsTrackWithEvent:event];
//业务异常,退出登录
[QGUserInfo logOut];
//失败回调
if (resultBlock) {
resultBlock(NO, nil);
}
}
} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
//添加刷新token失败埋点
QGAppBusinessStateEvent * event = [QGAppBusinessStateEvent abseEventWithPage:@"APP启动" action:@"刷新token" value:@"failed" code:nil desc:nil phone:[QGUserInfo sharedUserInfo].userName];
[QGAnalyticsService analyticsTrackWithEvent:event];
//请求失败,退出登录
[QGUserInfo logOut];
//失败回调
if (resultBlock) {
resultBlock(NO, nil);
}
}];
}
//未登录,处理回调
else
{
if (resultBlock) {
resultBlock(NO, nil);
}
}
} }
*/
#pragma mark - 检查升级 #pragma mark - 检查升级
/// 检查升级 /// 检查升级
......
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