美文网首页
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

    问题 项目的登录有微信快捷登录,然后在个人中心里面有绑定微信号。操作:【账号1】【微信号1】是绑定关系,使用【账号...

  • notification

    notification文档 桌面通知 notification 示例

  • Notification

    通知Notification

  • Android UI - Notification

    Notification Notification,通知。Android 里的通知设置无非下面几步:创建一个 No...

  • Android Notification的使用

    Notification的作用 能够在通知栏展示一些信息 Notification介绍 notification-...

  • Notification的基本使用和8.0适配

    Notification状态栏通知 1建造者模式构建通知类:Notification.Builder 2通知管理器...

  • 调用摄像头、FileProvider

    1.通知的更多效果  Notification notification = new NotificationCo...

  • 通知Notification

    通过建造者模式来创建通知。为了兼容低版本,v4 Support Library中提供了NotificationCo...

  • 通知(Notification)

    通知是您可以在应用的常规 UI 外部向用户显示的消息。当您告知系统发出通知时,它将先以图标的形式显示在通知区域中。...

  • Notification通知

    一.基本概念 ios提供了两种通知机制,本地通知,推送通知。 本地通知和推送通知可以让不在前端运行的程序告知用户程...

网友评论

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

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