24 @protocol CPUserNotificationCenterDelegate <
CPObject>
50 CPArray _deliveredNotifications;
51 CPArray _scheduledNotifications;
52 id <CPUserNotificationCenterDelegate> _delegate;
54 CPInteger _implementedDelegateMethods;
60 #pragma mark Creating Default User Notification Center 79 _deliveredNotifications = [];
80 _scheduledNotifications = [];
81 _timersForUserNotification = @{};
89 #pragma mark Getting and Setting the Delegate 91 - (void)setDelegate:(
id <CPUserNotificationCenterDelegate>)aDelegate
93 if (_delegate === aDelegate)
96 _delegate = aDelegate;
97 _implementedDelegateMethods = 0;
99 if ([_delegate respondsToSelector:
@selector(userNotificationCenter:shouldPresentNotification:)])
102 if ([_delegate respondsToSelector:
@selector(userNotificationCenter:didDeliverNotification:)])
105 if ([_delegate respondsToSelector:
@selector(userNotificationCenter:didActivateNotification:)])
111 #pragma mark Managing the Scheduled Notification Queue 129 [_scheduledNotifications addObject:anUserNotification];
130 _timersForUserNotification[[anUserNotification
UID]] = timer;
135 - (void)_scheduledUserNotificationTimerDidFire:(
CPTimer)aTimer
137 [
self deliverNotification:[aTimer
userInfo]];
146 if ([_scheduledNotifications indexOfObject:anUserNotification] !=
CPNotFound)
148 [_scheduledNotifications removeObject:anUserNotification];
149 [_timersForUserNotification[[anUserNotification
UID]] invalidate];
150 delete _timersForUserNotification[[anUserNotification
UID]];
156 #pragma mark Managing the Delivered Notifications 164 [
self _launchUserNotification:aNotification];
173 [_deliveredNotifications removeObject:aNotification];
179 - (void)removeAllDeliveredNotifications
181 [_deliveredNotifications removeAllObjects];
186 #pragma mark Permission Utilities 190 Notification.requestPermission(
function (permission) {
191 if (permission ==
"granted")
193 [
self _launchUserNotification:anUserNotification];
199 #pragma mark Notification Utilities 204 if (!window || !
'Notification' in window)
207 if (Notification.permission ===
'default')
208 [
self _askPermissionForUserNotification:anUserNotification];
210 if (Notification.permission ===
'granted')
212 if (([
self _delegateRespondsToShouldPresentNotification] && [
self _sendDelegateShouldPresentNotification:anUserNotification])
213 || ![
CPApp isActive])
215 var notification =
new Notification(
216 [anUserNotification title],
218 'body': [anUserNotification informativeText],
219 'icon': [[anUserNotification contentImage] filename],
221 'tag' : [anUserNotification identifier]
225 anUserNotification._presented = YES;
227 notification.onclick =
function () {
229 [
self _sendDelegateDidActivateNotification:anUserNotification];
236 notification.onclose =
function () {
242 anUserNotification._presented = NO;
246 anUserNotification._actualDeliveryDate = [
CPDate date];
247 [_deliveredNotifications addObject:anUserNotification];
249 if (![anUserNotification deliveryRepeatInterval])
250 [
self removeScheduledNotification:anUserNotification];
252 [
self _sendDelegateDidDeliverNotification:anUserNotification];
261 - (BOOL)_delegateRespondsToShouldPresentNotification
268 return [_delegate userNotificationCenter:self shouldPresentNotification:aNotification];
276 [_delegate userNotificationCenter:self didActivateNotification:aNotification];
284 [_delegate userNotificationCenter:self didDeliverNotification:aNotification];
294 - (CPArray)deliveredNotifications
296 return _deliveredNotifications;
302 - (void)setDeliveredNotifications:(CPArray)aValue
304 _deliveredNotifications = aValue;
310 - (CPArray)scheduledNotifications
312 return _scheduledNotifications;
318 - (void)setScheduledNotifications:(CPArray)aValue
320 _scheduledNotifications = aValue;
A representation of a single point in time.
global CPApp var CPUserNotificationCenterDelegate_userNotificationCenter_shouldPresentNotification_
The main run loop for the application.
id initWithFireDate:interval:target:selector:userInfo:repeats:(CPDate aDate, [interval] CPTimeInterval seconds, [target] id aTarget, [selector] SEL aSelector, [userInfo] id userInfo, [repeats] BOOL shouldRepeat)
CPRunLoop currentRunLoop()
CPTimeInterval deliveryRepeatInterval()
global CPApp var CPUserNotificationCenterDelegate_userNotificationCenter_didActivateNotification_
global CPApp var CPUserNotificationCenterDelegate_userNotificationCenter_didDeliverNotification_
The CPUserNotificationCenter class delivers user notifications to the user from applications or helpe...
var CPUserNotificationDefaultCenter
A timer object that can send a message after the given time interval.
CPTimeZone deliveryTimeZone()
Sends messages (CPNotification) between objects.
CPUserNotificationActivationTypeContentsClicked
void addTimer:forMode:(CPTimer aTimer, [forMode] CPString aMode)
CPUserNotificationAction typedef CPUserNotificationActivationType CPUserNotificationActivationTypeNone
The CPUserNotification class is used to configure a notification that is scheduled for display by the...