I am fresher for this application development field. I am tried to get notifications during user login & logout events. I have tried with NSWorkSpaceNotifications, but it does not working for me.
Can somebody help me please.
-(void)logInLogOutNotifications{
NSNotificationCenter *notCenter;
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
selector:@selector(observerMethod)
name:NSWorkspaceWillPowerOffNotification object:nil];
}
-(void)observerMethod:(NSNotification *)senderNotification;{
NSLog(@"System Logout Notification is called***********************");
}
NSApplicationMain Begin the RunLoop. You are calling logInLogOutNotifications function from main() function, so you shoud run runloop. or call logInLogOutNotifications in applicationDidFinishLaunching
-(void)logInLogOutNotifications{
NSNotificationCenter *notCenter;
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
selector:@selector(observerMethod)
name:NSWorkspaceWillPowerOffNotification object:nil];
[[NSRunLoop currentRunLoop] run];
}
Your method takes one argument, so you should change
@selector(observerMethod)
to
@selector(observerMethod:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With