protected override void ScheduleCallbackPlatformSpecific(ScheduledCallback callback)
        {
            // get the callback information. this can be null if we don't have all required information. don't schedule the notification if this happens.
            NSMutableDictionary callbackInfo = GetCallbackInfo(callback);

            if (callbackInfo == null)
            {
                return;
            }

            Action <UNNotificationRequest> requestCreated = request =>
            {
                lock (_callbackIdRequest)
                {
                    _callbackIdRequest.Add(callback.Id, request);
                }
            };

            IUNUserNotificationNotifier notifier = SensusContext.Current.Notifier as IUNUserNotificationNotifier;

            if (callback.Silent)
            {
                notifier.IssueSilentNotificationAsync(callback.Id, callback.NextExecution.Value, callbackInfo, requestCreated);
            }
            else
            {
                notifier.IssueNotificationAsync(callback.Protocol?.Name ?? "Alert", callback.UserNotificationMessage, callback.Id, callback.Protocol, true, callback.DisplayPage, callback.NextExecution.Value, callbackInfo, requestCreated);
            }
        }
Пример #2
0
        protected override void ScheduleCallbackAsync(string callbackId, TimeSpan delay, bool repeating, TimeSpan repeatDelay, bool repeatLag)
        {
            // get the callback information. this can be null if we don't have all required information. don't schedule the notification if this happens.
            DisplayPage         displayPage  = GetCallbackDisplayPage(callbackId);
            NSMutableDictionary callbackInfo = GetCallbackInfo(callbackId, repeating, repeatDelay, repeatLag, displayPage);

            if (callbackInfo == null)
            {
                return;
            }

            string userNotificationMessage = GetCallbackUserNotificationMessage(callbackId);

            Action <UNNotificationRequest> requestCreated = request =>
            {
                lock (_callbackIdRequest)
                {
                    _callbackIdRequest.Add(callbackId, request);
                }
            };

            IUNUserNotificationNotifier notifier = SensusContext.Current.Notifier as IUNUserNotificationNotifier;

            if (userNotificationMessage == null)
            {
                notifier.IssueSilentNotificationAsync(callbackId, delay, callbackInfo, requestCreated);
            }
            else
            {
                notifier.IssueNotificationAsync("Sensus", userNotificationMessage, callbackId, GetCallbackProtocolId(callbackId), true, displayPage, delay, callbackInfo, requestCreated);
            }
        }
        public override void CancelSilentNotifications()
        {
            UNUserNotificationCenter.Current.GetPendingNotificationRequests(requests =>
            {
                IUNUserNotificationNotifier notifier = SensusContext.Current.Notifier as IUNUserNotificationNotifier;

                foreach (UNNotificationRequest request in requests)
                {
                    if (TryGetCallback(request.Content?.UserInfo)?.Silent ?? false)
                    {
                        notifier.CancelNotification(request);
                    }
                }
            });
        }
Пример #4
0
        public override Task UpdateCallbacksAsync()
        {
            return(Task.Run(() =>
            {
                IUNUserNotificationNotifier notifier = SensusContext.Current.Notifier as IUNUserNotificationNotifier;

                // get a list of requests to update. cannot iterate over the requests directly because the raising
                // process is going to temporarily modify the collection.
                List <UNNotificationRequest> requests = null;
                lock (_callbackIdRequest)
                {
                    requests = _callbackIdRequest.Values.ToList();
                }

                foreach (UNNotificationRequest request in requests)
                {
                    TimeSpan timeTillTrigger = TimeSpan.Zero;
                    DateTime?triggerDateTime = (request.Trigger as UNCalendarNotificationTrigger)?.NextTriggerDate?.ToDateTime().ToLocalTime();
                    if (triggerDateTime.HasValue)
                    {
                        timeTillTrigger = triggerDateTime.Value - DateTime.Now;
                    }

                    // service any callback that should have already been serviced or will soon be serviced
                    if (timeTillTrigger.TotalSeconds < 5)
                    {
                        notifier.CancelNotification(request);
                        ServiceCallbackAsync(request.Content?.UserInfo);
                    }
                    // all other callbacks will have upcoming notification deliveries, except for silent notifications, which were canceled when the
                    // app was backgrounded. re-issue those silent notifications now.
                    else if (iOSNotifier.IsSilent(request.Content?.UserInfo))
                    {
                        notifier.IssueNotificationAsync(request.Identifier, request.Content, timeTillTrigger, newRequest =>
                        {
                            lock (_callbackIdRequest)
                            {
                                _callbackIdRequest[request.Identifier] = newRequest;
                            }
                        });
                    }
                }
            }));
        }
        public override void UpdateCallbackNotifications()
        {
            lock (_callbackIdRequest)
            {
                IUNUserNotificationNotifier notifier = SensusContext.Current.Notifier as IUNUserNotificationNotifier;

                // copy key list since servicing/raising the callback is going to modify the collection temporarily
                foreach (string callbackId in _callbackIdRequest.Keys.ToList())
                {
                    UNNotificationRequest request = _callbackIdRequest[callbackId];

                    double   msTillTrigger   = 0;
                    DateTime?triggerDateTime = (request.Trigger as UNCalendarNotificationTrigger)?.NextTriggerDate?.ToDateTime().ToLocalTime();
                    if (triggerDateTime.HasValue)
                    {
                        msTillTrigger = (triggerDateTime.Value - DateTime.Now).TotalMilliseconds;
                    }

                    // service any callback that should have already been serviced or will soon be serviced
                    if (msTillTrigger < 5000)
                    {
                        notifier.CancelNotification(request);
                        ServiceCallbackAsync(request.Content?.UserInfo);
                    }
                    // all other callbacks will have upcoming notification deliveries, except for silent notifications, which were canceled when the
                    // app was backgrounded. re-issue those silent notifications now.
                    else if (iOSNotifier.IsSilent(request.Content?.UserInfo))
                    {
                        notifier.IssueNotificationAsync(callbackId, request.Content, msTillTrigger, newRequest =>
                        {
                            _callbackIdRequest[callbackId] = newRequest;
                        });
                    }
                }
            }
        }