123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- //
- // BlackDoorManager+click.m
- // SikeyComm
- //
- // Created by 刘振兴 on 2025/2/25.
- // Copyright © 2025 BaH Cy. All rights reserved.
- //
- #import "BlackDoorManager+click.h"
- #import "BlackDoorManager+data.h"
- #define KEY_BDM_USERCLICK_HEADER @"@BDM*"
- #define KEY_BDM_CLICK_TAG 1234567890
- #define BDM_BUTTON_CLICK_SIZE 90
- #define BDM_BUTTON_SERVER_SIZE_WIDTH 120
- #define BDM_BUTTON_SERVER_SIZE_HEIGHT 50
- #define TIME_INTERVAL_MAX 8
- #define BDM_CLICK_ORDER @"323"
- @implementation BlackDoorManager (click)
- + (void)addBlackDoorButtons:(UIView*)supperView {
- for (NSInteger i = 1; i <= 4; i++) {
- UIButton* button = [[UIButton alloc] init];
- button.tag = KEY_BDM_CLICK_TAG + i;
- [button setBackgroundColor:[UIColor clearColor]];
- [supperView addSubview:button];
-
- CGFloat x = ((i == 1) || (i == 3))? 0 : (BDM_SCREEN_WIDTH - BDM_BUTTON_CLICK_SIZE);
- CGFloat y = ((i == 1) || (i == 2))? 60 : (BDM_SCREEN_HEIGHT - BDM_BUTTON_CLICK_SIZE) - 40;
- [button setFrame:CGRectMake(x, y, BDM_BUTTON_CLICK_SIZE, BDM_BUTTON_CLICK_SIZE)];
- [button addTarget:self action:@selector(blButtonClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- }
- + (void)blButtonClick:(UIButton*)button {
- NSInteger index = button.tag % KEY_BDM_CLICK_TAG ;
- NSLog(@"BlackDoorManager: index:%ld", (long)index);
- [self blButtonClickEx:index supperView:[button superview]];
- }
- + (void)blButtonClickEx:(NSInteger)index supperView:(UIView*)supperView {
- switch (index) {
- case 1: {
- //清空点击消息
- [self clearUserClickInfo];
-
- NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
- NSString *info = [NSString stringWithFormat:@"%@_%@_",KEY_BDM_USERCLICK_HEADER, @(timestamp)];
- [self setUserClickInfo:info];
- break;
- }
- case 2:
- case 3: {
- //点击信息不全
- NSString* info = [self getUserClickInfo];
- NSArray* array = [info componentsSeparatedByString:@"_"];
- if (array.count < 2) {
- [self showTosat:@"请重新点击(跳点)" supperView:supperView];
- [self clearUserClickInfo];
- break;
- }
-
- //验证头字串不对
- NSString* header = array[0];
- if (![header isEqualToString:KEY_BDM_USERCLICK_HEADER]) {
- [self showTosat:@"请重新点击(校验错误)" supperView:supperView];
- [self clearUserClickInfo];
- break;
- }
-
- [self setUserClickInfo:[NSString stringWithFormat:@"%@%@", info, @(index)]];
- break;
- }
- case 4: {
- //点击信息不全
- NSString* info = [self getUserClickInfo];
- NSArray* array = [info componentsSeparatedByString:@"_"];
- if (array.count < 3) {
- [self showTosat:@"请重新点击(跳点)" supperView:supperView];
- [self clearUserClickInfo];
- break;
- }
-
- //验证头字串不对
- NSString* header = array[0];
- if (![header isEqualToString:KEY_BDM_USERCLICK_HEADER]) {
- [self showTosat:@"请重新点击(校验错误)" supperView:supperView];
- [self clearUserClickInfo];
- break;
- }
-
- //点击超时
- NSTimeInterval beginTime = [array[1] integerValue];
- NSTimeInterval nowTime = [[NSDate date] timeIntervalSince1970];
- if (nowTime > beginTime && (nowTime - beginTime > TIME_INTERVAL_MAX)) {
- [self showTosat:[NSString stringWithFormat:@"请重新点击(%d秒超时)", TIME_INTERVAL_MAX] supperView:supperView];
- [self clearUserClickInfo];
- break;
- }
-
- //点击顺序不对
- NSString* order = array[2];
- if (![order isEqualToString:BDM_CLICK_ORDER]) {
- [self showTosat:@"请重新点击(顺序不对)" supperView:supperView];
- [self clearUserClickInfo];
- break;
- }
-
- //验证通过
- [self showBlackDoorView:supperView];
- break;
- }
- default:
- break;
- }
- }
- //验证通过
- + (void)showBlackDoorView:(UIView*)supperView {
- BlackDoorManager* view = [[BlackDoorManager alloc] initWithFrame:supperView.bounds];
- [supperView addSubview:view];
- }
- + (void)showTosat:(NSString *)strMsg supperView:(UIView*)supperView {
- NSInteger serverType = [ServerManager getServerType];
- if (serverType == 0)
- return;
- [EasyTextView showText:strMsg];
- }
- @end
|