#import <Foundation/Foundation.h>
#define CHILD_WEAK_NOTIFC @"childe_week" @interface Child : NSObject
@property (nonatomic,assign) int age;
@property (nonatomic,assign) NSInteger sleep;
@end
#import "Child.h"

@implementation Child

-(id) init{
self=[super init];
if(self!=nil){
_sleep=100;
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeAction:) userInfo:nil repeats:YES];
}
return self;
} -(void) timeAction:(NSTimer *) timer{
_sleep-=2;
NSLog(@"%ld",_sleep);
if(_sleep<90){
//发送通知
[[NSNotificationCenter defaultCenter] postNotificationName:CHILD_WEAK_NOTIFC object:[NSNumber numberWithInteger:_sleep]];
[timer invalidate];
}
}
@end
#import <Foundation/Foundation.h>

@interface Father : NSObject

@end
#import "Father.h"
#import "Child.h" @implementation Father
-(id)init{
self=[super init]; if(self!=nil){
//接收通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weakNotification:) name:CHILD_WEAK_NOTIFC object:nil];
}
return self;
}
-(void)weakNotification:(NSNotification *) notification{ NSLog(@"sdkjflskdjf");
NSNumber *number=notification.object; NSLog(@"%@",number);
}
@end
Child *child=[[Child alloc]init];
Father *father=[[Father alloc]init];
NSLog(@"%@",child);
[[NSRunLoop currentRunLoop] run];

通知---iOS的更多相关文章

  1. 推送通知iOS客户端编写实现及推送服务器端编写

    http://blog.csdn.net/tonny_guan/article/details/8963262 1.iOS客户端编程 推送通知技术在Mac OS X和iOS系统上都可以运行,我们本章主 ...

  2. 极光推送能获取 registrationId,但是接收不到通知 - iOS

    集成极光推送进行调试的时候,运行 App 可以正常获取 registrationId,但是却迟迟无法收到推送消息,而Android 端是可以正常收到消息; 检查了证书配置和极光的配置一切正常,便开始返 ...

  3. ios推送:本地通知UILocalNotification

    Notification是智能手机应用编程中非常常用的一种传递信息的机制,而且可以非常好的节省资源,不用消耗资源来不停地检查信息状态(Pooling),在iOS下应用分为两种不同的Notificati ...

  4. iOS学习笔记22-推送通知

    一.推送通知 推送通知就是向用户推送一条信息来通知用户某件事件,可以在应用退到后台后,或者关闭后,能够通过推送一条消息通知用户某件事情,比如版本更新等等. 推送通知的常用应用场景: 一些任务管理APP ...

  5. Phonegap 之 iOS银联在线支付(js调用ios端银联支付控件)

    Phonegap项目,做支付的时候,当把网站打包到ios或android端成app后,在app上通过wap调用银联在线存在一个问题: 就是当从银联支付成功后,再从服务器返回到app客户端就很难实现. ...

  6. iOS开发200个tips总结(一)

    tip 1 :  给UIImage添加毛玻璃效果 func blurImage(value:NSNumber) -> UIImage { let context = CIContext(opti ...

  7. iOS企业级开发初级课程-表视图(13集)

    首先了解了表视图的组成.表视图类的构成.表视图的分类以及表视图的两个重要协议(委托协议和数据源协议),对表视图有了一个整体上的认识.接下来我们掌握了如何实现简单表视图和分节表视图,以及表视图中索引.搜 ...

  8. iOS开发---iPhone SDK 包含哪些东西?

    第一部分: 在使用Intel芯片的Macintosh计算机开发iOS应用程序所需的全部接口.工具以及资源全都包含于iPhone SDK. 苹果公司将大部分系统接口发布在框架这种特殊的数据包.一个框架就 ...

  9. iOS 10.0 更新点(开发者视角)

    html, body {overflow-x: initial !important;}html { font-size: 14px; } body { margin: 0px; padding: 0 ...

  10. [iOS]iPhone推送原理

    推送原理,先上图 说一下原理吧, 由App向iOS设备发送一个注册通知 iOS向APNs远程推送服务器发送App的Bundle Id和设备的UDID APNs根据设备的UDID和App的Bundle ...

随机推荐

  1. 转 15款免费WiFi(入侵破解)安全测试工具

    转:http://www.ctocio.com/security/cloudsecurity/6594.html 一.Vistumbler扫描器 WiFi 扫描器能能发现附近AP的详细信息,例如信号强 ...

  2. WEB ui快速构建

    http://www.runoob.com/bootstrap/bootstrap-ui-editor.html 1http://pingendo.com/ 2http://www.layoutit. ...

  3. 使用respondsToSelector:来发现对象是否响应消息

    发现对象是否响应消息 要发现一个对象是否响应一则消息,请在该对象上调用 respondsToSelector: 方法.应用程序代码通常验证一个对象响应一则消息后,才将消息发送给该对象. if ([it ...

  4. BZOJ 3450 Easy

    注意细节啊... 和上一道差不多. #include<iostream> #include<cstdio> #include<cstring> #include&l ...

  5. PB常用日期

    用一条语句写成的有关日期函数 //1.生肖(年份参数:int ls_year  返回参数:string): mid(fill('鼠牛虎兔龙蛇马羊猴鸡狗猪',48),(mod(ls_year -1900 ...

  6. HDOJ-三部曲-多重背包-1014-Cash Machine

    通过这道题我基本了解了利用二进制对多重背包问题进行优化的思想. Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submiss ...

  7. C++ algorithm 里的sort函数应用

    MSDN中的定义: template<class RanIt>    void sort(RanIt first, RanIt last); //--> 1)template< ...

  8. HTTP Live Streaming直播(iOS直播)技术分析与实现

    前些日子,也是项目需要,花了一些时间研究了HTTP Live Streaming(HLS)技术,并实现了一个HLS编码器HLSLiveEncoder,当然,C++写的.其功能是采集摄像头与麦克风,实时 ...

  9. HDU 5009

    http://acm.hdu.edu.cn/showproblem.php?pid=5009 题意:一个数列,每个点代表一种颜色,每次选一个区间覆盖,覆盖的代价是区间内颜色种类数的平方,直到覆盖整个数 ...

  10. SQL基础,与数据类型;

    net start mssqlserver 开启数据库:  net stop mssqlserver 关闭数据库:  net pause mssqlserver 暂停数据库:  net continu ...