3

를 호출이 호출NSUserNotification 가까이 내가 <code>NSUserNotification</code>에 닫기 버튼을 클릭 맥 OS 10.13 매번 때문에 didActivateNotification

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification 

나는이 문제를 방지하거나 알림을 만들려면 action 버튼

를 대 close을 처리 할 수있는 방법 내가 수행합니다 .plist

NSUserNotification *notification = [[NSUserNotification alloc] init]; 
... 
[notification setHasActionButton:false]; 
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; 
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:(id)self]; 

NSUserNotificationAlertStyle 0 "으로 설정"

하지만 이제 기본적으로 닫기 버튼은 actionButton과 같은 방식으로 반응합니다.

답변

1

NSUserNotification이 속성이있는 사용자가 관리 할 수있는 알림 식별자 또는 hasActionButton 값을 반환하므로 동일한 위임 메서드에서 else와 함께 액션 버튼을 처리 할 수 ​​있습니다.

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification{  
} 
+0

속성은 무엇입니까? – maxisme

+0

https://developer.apple.com/documentation/foundation/nsusernotification?language=objc 여기에서 사용할 수있는 조건 세부 정보를 얻고 조건부 조치를 작성합니다. –

1

이 나를 위해 작품입니다 ..

당신이 didActivateNotification: 방법으로 통지를 제거 할 수 있습니다 center

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification 
{ 
    NSLog(@"Notification - Clicked"); 
    [center removeDeliveredNotification: notification]; 
    notification=nil; 
} 

...

NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter]; 
    [center scheduleNotification:notification];