시스템의 전원을 끄거나 재시작하거나 사용자가 로그 아웃하려고 할 때 알림을받을 수 있습니다. 이는 일반적인 알림이 아니라 작업 공간 알림입니다.
당신은이 같은 알림을 등록 할 수 있습니다
- (void)workspaceWillPowerOff:(NSNotification *)notification
{
self.powerOffRequestDate = [NSDate new];
}
가에
@property (atomic,strong,readwrite) NSDate *powerOffRequestDate;
추가 : 알림 처리기
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
//...more code...
self.powerOffRequestDate = [NSDate distantPast];
NSNotificationCenter *wsnCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[wsnCenter addObserver:self
selector:@selector(workspaceWillPowerOff:)
name:NSWorkspaceWillPowerOffNotification
object:nil];
}
을, 당신은 단지 날짜를 멀리 저장해야 적절한 장소.
앱 종료를 요구하는 경우 해당 날짜를 가져와 컴퓨터가 곧 종료되는지 확인해야합니다.
다음과 같은 경우에 5 분 간격을 선택했습니다. 컴퓨터가 꺼져야하지만 다른 앱에서이를 취소해야합니다. 앱이 아직 실행 중입니다. 10 분 후 사용자가 앱을 종료합니다. 이 경우 앱은으로 사용자에게 문의해야합니다. 이것은 조금은 해킹이지만, 생각하는 "미친 해킹"이 아닙니다 ...
희망이 있습니다.