ios验证码发送次数过多(iOSNSProxyRuntime)

发布日期:2024-12-22 02:32:39     作者:猫你爸     手机:https://m.xinb2b.cn/know/jdn106794.html     违规举报

NSProxy是一个抽象类,它并没有继承NSObject,它实现了NSObject协议,可以利用NSProxy Runtime 解决循环引用的问题,接下来我们就来聊聊关于ios验证码发送次数过多?以下内容大家不妨参考一二希望能帮到您!


ios验证码发送次数过多

NSProxy是一个抽象类,它并没有继承NSObject,它实现了NSObject协议,可以利用NSProxy Runtime 解决循环引用的问题

其实现如下:

#import "HCQProxy.h"@interface HCQProxy()@property(nonatomic, weak)NSObject* target;@end@implementation HCQProxy#pragma mark - NSProxy 没有初始化方法,需要手动实现- (instancetype)initWithTarget:(NSObject*)target { _target = target; return self;} (instancetype)proxyWithTarget:(id)target { HCQProxy* proxy = [[HCQProxy alloc]initWithTarget:target]; return proxy;}#pragma mark - 获得方法的方法签名-(NSMethodSignature*)methodSignatureForSelector:(SEL)sel { NSMethodSignature* signature = (_target) ? [_target methodSignatureForSelector:sel] : [super methodSignatureForSelector:sel] ; return signature;}#pragma mark - 为调用设置目标-(void)forwardInvocation:(NSInvocation *)invocation { if(!_target) return; [invocation invokeWithTarget:_target];}@end

写了例子验证一下

#import "UserViewController.h"@import HCQProxy.HCQProxy;@interface UserViewController ()@property(nonatomic,strong)NSTimer* timer;@endstatic int count;@implementation UserViewController- (void)viewDidLoad { [super viewDidLoad]; self.titleS = @"用户中心"; self.leftBtnClickHandler = ^(id _Nullable target) { UserViewController* vc = (UserViewController*)target; [vc.navigationController popViewControllerAnimated:YES]; };}-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:[HCQProxy proxyWithTarget:self] selector:@selector(doSomething) userInfo:nil repeats:YES];}-(void)doSomething { NSLog(@"count = %d",count );}-(void)dealloc { //NSLog(@"%s %@",__func__,_timer); if(_timer) { [_timer invalidate]; _timer = nil; } //NSLog(@"%s %@",__func__,_timer);}@end

 
 
本文地址:https://xinb2b.cn/know/jdn106794.html,转载请注明出处。

推荐图文
推荐经验知识
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  违规举报  |  蜀ICP备18010318号-4  |  百度地图  | 
Processed in 0.118 second(s), 1 queries, Memory 2.37 M