3

Depuis Mac OS 10.13 chaque fois que je clique sur le bouton de fermeture sur une NSUserNotification appelle:NSUserNotification proximité appelle didActivateNotification

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

Comment puis-je empêcher cela ou gérer le close vs le bouton action

Pour créer la notification Je fais:

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

et NSUserNotificationAlertStyle dans le .plist est réglé sur "0 Mais maintenant, le bouton de fermeture réagit de la même manière que le actionButton?

Répondre

1

NSUserNotification a la propriété à partir de laquelle vous pouvez gérer identificateur de notification ou valeur de hasActionButton, de sorte que vous pouvez gérer le bouton close ou le bouton d'action avec if else dans la même méthode de délégation

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

Quelle est la propriété? – maxisme

+0

https://developer.apple.com/documentation/foundation/nsusernotification?language=objcci vous obtiendrez les informations sur les propriétés que vous pouvez utiliser pour écrire l'action conditionnelle. –

1

C'est fonctionne pour moi ..

vous pouvez supprimer notification didActivateNotification: méthode

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

center est ...

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