美文网首页
iOS-踩坑通知Notification

iOS-踩坑通知Notification

作者: 不明Xia落 | 来源:发表于2019-03-13 17:51 被阅读0次

    问题

    项目的登录有微信快捷登录,然后在个人中心里面有绑定微信号。
    操作:【账号1】【微信号1】是绑定关系,使用【账号2】绑定【微信号1】结果登陆了微信号1指向的账号1 。

    分析

    因为只调用了绑定接口,并没有多调用其他接口。所以认为是接口的问题。接口说调用了登录接口。所以导致重新登录了这个微信账号指向的账户。
    一开始我是不行的,明明我只是调用了一个接口为什么会多调用呢?肯定是接口那边做了其他的类似重定向的操作。
    为了更好的怼回去,我决定拿出证据出来。

    debug

    在网络请求类中打个断点,让每次请求都停一下。点击绑定微信,调用绑定接口,接着又调用了登录接口。登录接口??又?蒙蔽。。
    到登录页面检查,登录页面使用了通知。当微信授权成功后调用登录方法。这个登录方法只有微信授权成功才会去掉。难道是通知没有移除?

    - (void)dealloc
    {
        [self removeNotification];
    }
    
    #pragma mark - notification
    - (void)addNotification {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wxLoginSuccessAction:) name:NOTICE_WXLogIn object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipaySuccessAction:) name:NOTICE_AliPay object:nil];
    }
    
    - (void)removeNotification {
        [[NSNotificationCenter defaultCenter] removeObserver:self name:NOTICE_WXLogIn object:nil];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:NOTICE_AliPay object:nil];
    }
    

    检查了一下,移除的代码是写了。但是为什么没有移除呢?这段代码没有执行?
    在 dealloc 处打断点,发现确实是没有走。

    解决

    检查登录页面的controller代码,发现block中强引用了self。改为弱引用。

    - (void)createOtherLogin
    {
        __weak typeof(self) weakSelf = self;
        QuickLoginView *otherLogin = [[QuickLoginView alloc] init];
        [self.view addSubview:otherLogin];
        otherLogin.alipayLoginAction = ^(UIButton * _Nonnull sender) {
            [weakSelf aliPayLoginAction:sender];
        };
        otherLogin.wxLoginAction = ^(UIButton * _Nonnull sender) {
            [weakSelf weChatLoginAction:sender];
        };
        [otherLogin mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_offset(0);
            make.height.mas_equalTo(120*WIDTHRADIUS);
        }];
    }
    

    联想

    怪不得app崩溃率一致居高不下,原来登录页面一直没有释放。

    相关文章

      网友评论

          本文标题:iOS-踩坑通知Notification

          本文链接:https://www.haomeiwen.com/subject/efalpqtx.html