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#******

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

  • 相关阅读:
    ORACLE时间函数(SYSDATE)简析
    RestTemplate请求
    Java中ASM框架详解
    java进阶
    Java,Mysql-根据一个给定经纬度的点,进行附近500米地点查询–合理利用算法
    JAVA程序员必看的15本书-JAVA自学书籍推荐
    Linux curl命令详解
    Java 集合系列06之 Vector详细介绍(源码解析)和使用示例
    腾讯信鸽推送Android SDK快速指南
    信鸽推送.NET SDK 开源
  • 原文地址:https://www.cnblogs.com/fkunlam/p/5804277.html
Copyright © 2011-2022 走看看