NotificationCenter 1.1.0

NotificationCenter 1.1.0

jackiehu 维护。



  • 作者
  • HU

NSNotification

使用 block 方式使用 NSNotification,其中通知以异步方式发送,不会阻塞线程

发送通知

    [[NotificationCenter defaultNotificationCenter] postNotificationName:@"name" object:@"11111111111"];

接收通知

    [[NotificationCenter defaultNotificationCenter] addObserverWithName:@"name" callBack:^(NSNotification * _Nonnull noti) {
        NSLog(@"%@",noti.object);
    }];

移除通知 页面需要移除通知不然会多次接收通知

    [[NotificationCenter defaultNotificationCenter] removeObserver];

安装方式

1.手动添加

  • 1.将 NotificationCenter 文件夹添加到工程目录中
  • 2.导入 NotificationCenter.h

2.CocoaPods

  • 1.在 Podfile 中添加 pod 'NotificationCenter'
  • 2.执行 pod install 或 pod update
  • 3.导入NotificationCenter.h