Notificaciones locales
let nc = NotificationCenter.default // Note that default is now a property, not a method call
nc.addObserver(self,
selector: #selector(handleNotification),
name: NSNotification.Name(rawValue: AppConstants.Notifications.ARASAACPicto),
object: nil);
let nc = NotificationCenter.default // Note that default is now a property, not a method call
nc.removeObserver(self, name: NSNotification.Name(rawValue: AppConstants.Notifications.ARASAACPicto), object: nil)
let nc = NotificationCenter.default
nc.post(name:NSNotification.Name(rawValue: AppConstants.Notifications.ARASAACPicto),
object: nil,
userInfo: ["selectedPicture":selectedPicture as Any])
@objc func handleNotification(notification: NSNotification){
imageType = AppConstants.ImageType.ARASAAC;
categoryPicture = notification.userInfo!["selectedPicture"] as? Picture;
}
En el viewController
1) para suscribir:
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receivedRemoteCommandCenterNotification)
name:REMOTE_COMMAND_CENTER_NOTIFICATION
object:nil];
}
2) para desuscribir:
-(void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
SI SE QUIERE ELIMINAR LA NOTIFICACION EN CONCRETO (NO TODAS):
[[NSNotificationCenter defaultCenter] removeObserver:self name:REMOTE_COMMAND_CENTER_NOTIFICATION object:nil];
3) para lanzarla desde cualquier punto:
[[NSNotificationCenter defaultCenter]
postNotificationName:REMOTE_COMMAND_CENTER_NOTIFICATION
object:self];