zoukankan      html  css  js  c++  java
  • 通知PostNotification

    //
    //  ViewController.m
    //  FKLTest
    //
    //  Created by kun on 16/8/10.
    //  Copyright © 2016年 kun. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "FKLTool.h"
    #import "XMGDownloadTool.h"
    #import "PostNotificationViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        NSLog(@"******#receiveNotification--Begin#******");
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification) name:@"postNotification" object:nil];
        NSLog(@"******#receiveNotification--End#******");
    
    }
    
    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        PostNotificationViewController *postVc = [[PostNotificationViewController alloc] init];
        
        [self presentViewController:postVc animated:YES completion:nil];
    }
    
    - (void)receiveNotification
    {
        NSLog(@"---begin---%s", __func__);
        sleep(5.0);
        NSLog(@"---after---%s", __func__);
    }
    
    @end
    //
    //  PostNotificationViewController.m
    //  FKLTest
    //
    //  Created by kun on 16/8/24.
    //  Copyright © 2016年 kun. All rights reserved.
    //
    
    #import "PostNotificationViewController.h"
    
    @interface PostNotificationViewController ()
    
    @end
    
    @implementation PostNotificationViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        NSLog(@"******#postNotification--Begin#******");
        [[NSNotificationCenter defaultCenter] postNotificationName:@"postNotification" object:nil];
        NSLog(@"******#postNotification--End#******");
    }
    
    @end
    2016-08-24 18:54:07.713 FKLTest[1186:24510] ******#receiveNotification--Begin#******
    2016-08-24 18:54:07.714 FKLTest[1186:24510] ******#receiveNotification--End#******
    2016-08-24 18:56:15.805 FKLTest[1186:24510] ******#postNotification--Begin#******
    2016-08-24 18:56:15.806 FKLTest[1186:24510] ---begin----[ViewController receiveNotification]
    2016-08-24 18:56:20.807 FKLTest[1186:24510] ---after----[ViewController receiveNotification]
    2016-08-24 18:56:20.808 FKLTest[1186:24510] ******#postNotification--End#******

    分析:监听通知必须要在发送通知之前设置好。发送通知,如果有监听此通知的观察者,会等待观察者的监听方法处理完后才会返回;如果没有则立马返回。

  • 相关阅读:
    maven第三章 maven使用入门
    各个软件产生的原因
    maven的pom.xml深入理解
    批量同步订单信息(包括状态)到订单中心心得
    数据库连接超时和go away、如何检测数据库的最大连接数
    记录错误日志的技巧
    架构思想总结同步和事务的具体应用
    业务逻辑复杂性处理
    日志系统总结
    php捕获异常的处理
  • 原文地址:https://www.cnblogs.com/fkunlam/p/5804277.html
Copyright © 2011-2022 走看看