Estoy desarrollando una aplicación en Xcode para Mac y me gustaría saber el evento que se dispara cuando el Mac vuelve de estar dormido. AmaweFromNib no parece funcionar.¿Qué evento se desencadena cuando Mac vuelve de estar dormido?
Gracias!
Estoy desarrollando una aplicación en Xcode para Mac y me gustaría saber el evento que se dispara cuando el Mac vuelve de estar dormido. AmaweFromNib no parece funcionar.¿Qué evento se desencadena cuando Mac vuelve de estar dormido?
Gracias!
acaba de encontrar:
- (void) receiveWakeNote: (NSNotification*) note
{
NSLog(@"receiveSleepNote: %@", [note name]);
}
- (void) fileNotifications
{
//These notifications are filed on NSWorkspace's notification center, not the default
// notification center. You will not receive sleep/wake notifications if you file
//with the default notification center.
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
selector: @selector(receiveWakeNote:)
name: NSWorkspaceDidWakeNotification object: NULL];
}
Puede utilizar IORegisterForSystemPower().
conecta la llamada al dominio IOService Raíz de energía con el fin de recibir el sueño & notificaciones vigilia para el sistema. No proporciona el cierre del sistema y reinicia las notificaciones.
io_connect_t IORegisterForSystemPower (
void *refcon,
IONotificationPortRef *thePortRef,
IOServiceInterestCallback callback,
io_object_t *notifier) ;
Tome un vistazo a Q:How can my application get notified when the computer is going to sleep or waking from sleep? How to I prevent sleep?
para SWIFT 3:
func onWakeNote(note: NSNotification) {
print("Received wake note: \(note.name)")
}
func onSleepNote(note: NSNotification) {
print("Received sleep note: \(note.name)")
}
func fileNotifications() {
NSWorkspace.shared().notificationCenter.addObserver(
self, selector: #selector(onWakeNote(note:)),
name: Notification.Name.NSWorkspaceDidWake, object: nil)
NSWorkspace.shared().notificationCenter.addObserver(
self, selector: #selector(onSleepNote(note:)),
name: Notification.Name.NSWorkspaceWillSleep, object: nil)
}
dos cosas: que quieres "nulo" no "NULO" para su objeto, y se debe formatear su respuesta para mostrar su código como código formateado, es bastante ilegible en este momento. ¡Pero es un buen trabajo responder tu propia pregunta! –
¿Cómo puedo formatear correctamente el código? No sé la etiqueta requerida ... ¡Gracias! –
Parece que Parag te ganó. Pero en el futuro, mira los botones en el editor. Uno de ellos es un par de llaves ("{}"). Use esto para formatear un bloque de texto seleccionado como código. –