我正在使用这个方法:
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = @"Title";
notification.informativeText = @"body";
notification.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];如何让它在3秒后超时?
发布于 2014-09-17 17:40:29
将NSTimer设置为三秒钟后触发,然后使用NSUserNotificationCenter的removeDeliveredNotification删除通知。
例如,为了简洁和清晰,使用NSTimer+blocks:
[NSTimer scheduledTimerWithTimeInterval:3.0 block:^
{
[[NSUserNotificationCenter defaultUserNotificationCenter] removeDeliveredNotification: notification];
} repeats:NO];请注意,这并不是关于使用NSTimer类别的说明或建议-- API并不是很好:-)
发布于 2014-09-18 20:27:31
我自己解决了这个问题!我使用usleep()等待,然后在3秒后将其删除。希望这能有所帮助
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = @"Upload Failed!";
notification.informativeText = @"Error reading data.";
notification.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
usleep(3000000); //waits for 3 seconds
[[NSUserNotificationCenter defaultUserNotificationCenter] removeDeliveredNotification: notification];https://stackoverflow.com/questions/25870550
复制相似问题