NSUserNotification no muestra el botón de acción
Estoy usando este código:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSUserNotification *notification = [[NSUserNotification alloc] init];
[notification setTitle: @"Title"];
[notification setSubtitle: @"Subtitle"];
[notification setInformativeText: @"Informative Text"];
[notification setHasActionButton: YES];
[notification setActionButtonTitle: @"Action Button"];
[notification setOtherButtonTitle: @"Other Button"];
[notification setSoundName: NSUserNotificationDefaultSoundName];
[notification setDeliveryDate: [NSDate dateWithTimeIntervalSinceNow: 10]];
[[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification: notification];
}
Y estoy consiguiendo, sin falta,
No hay botón de acción, u otro botón.
4 answers
Como ya se indicó en una respuesta anterior, el tipo de notificación debe configurarse para alertar para que se muestre el botón de acción. Si desea establecer el estilo de notificación predeterminado de su aplicación para alert, debe definir la clave NSUserNotificationAlertStyle en info.plist con el valor alert.
Ver la información de Apple .plist keys reference para más detalles:
NSUserNotificationAlertStyle Especifica si el estilo de notificación debe ser banners, alertas, o none. El valor predeterminado es banners, que es el estilo recomendado.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-17 20:45:43
Y aquí estaba la respuesta.
Gracias de nuevo a #macdev en freenode.
La selección debe ser "Alerts" para tener botones.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-26 19:29:28
Como una instancia contraria para otras respuestas, podemos usar iTunes, que todavía muestra el botón "Skip" incluso cuando configuramos el estilo de alerta para banners. Así que continué buscando y encontré este repositorio de github donde Indragie Karunaratne proporciona algunas propiedades adicionales útiles en los encabezados privados de NSUserNotification. Puede consultar la lista completa de las propiedades en NSUserNotification_Private.h archivo, pero real para mostrar botones en estilo de notificación de banner is
@property BOOL _showsButtons; // @dynamic _showsButtons;
Así que puedes añadir esta línea a tu código
[notification setValue:@YES forKey:@"_showsButtons"];
Y su botón de acción de notificación se volverá independiente en el estilo de alerta.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-04-15 15:02:39
El comando mágico basado en la respuesta de PARTISAN es:
notification.set_showsButtons_(True)
Cha-ching:)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-22 08:26:04