现在的位置: 首页 > 综合 > 正文

NSNotificationCenter使用

2018年02月03日 ⁄ 综合 ⁄ 共 891字 ⁄ 字号 评论关闭
<span style="font-family: Arial, Helvetica, sans-serif;">1.注册NotificationCenter</span>

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationPosedAction:) name:@"notificationPosed" object:nil];

2.NotificationCenter事件

-(void)notificationPosedAction:(NSNotification *)notif{
    NSString * state = [notif object];
    NSLog(@"%@",state);
}

3.触发事件

 NSString * s = @"hehe";
    [[NSNotificationCenter defaultCenter] postNotificationName:@"<span style="font-family: Arial, Helvetica, sans-serif;">notificationPosed</span><span style="font-family: Arial, Helvetica, sans-serif;">" object:s];</span>

4.移除

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"<span style="font-family: Arial, Helvetica, sans-serif;">notificationPosed</span><span style="font-family: Arial, Helvetica, sans-serif;">" object:nil];</span>

5判断推送是否打开

UIRemoteNotificationTypeNone == [[UIApplication sharedApplication] enabledRemoteNotificationTypes]

抱歉!评论已关闭.