public async Task RequestNotificationsAsync(bool gpsIsRunning)
        {
            UNUserNotificationNotifier notifier = SensusContext.Current.Notifier as UNUserNotificationNotifier;

            foreach (string id in CallbackIds)
            {
                if (TryGetCallback(id) is ScheduledCallback callback)
                {
                    using (NSMutableDictionary callbackInfo = GetCallbackInfo(callback))
                    {
                        if (callbackInfo != null)
                        {
                            if (callback.Silent == false)
                            {
                                await notifier.IssueNotificationAsync(callback.Protocol?.Name ?? "Alert", callback.UserNotificationMessage, callback.Id, true, callback.Protocol, null, callback.NotificationUserResponseAction, callback.NotificationUserResponseMessage, callback.NextExecution.Value, callbackInfo);
                            }
                            else
                            {
                                await RequestRemoteInvocationAsync(callback);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override async Task RequestLocalInvocationAsync(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[callback.Id] = request;
                }
            };

            UNUserNotificationNotifier notifier = SensusContext.Current.Notifier as UNUserNotificationNotifier;

            if (callback.Silent)
            {
                await notifier.IssueSilentNotificationAsync(callback.Id, callback.NextExecution.Value, callbackInfo, requestCreated);
            }
            else
            {
                await notifier.IssueNotificationAsync(callback.Protocol?.Name ?? "Alert", callback.UserNotificationMessage, callback.Id, true, callback.Protocol, null, callback.NotificationUserResponseAction, callback.NotificationUserResponseMessage, callback.NextExecution.Value, callbackInfo, requestCreated);
            }
        }
        public async Task CancelNotificationsAsync()
        {
            UNUserNotificationNotifier notifier = SensusContext.Current.Notifier as UNUserNotificationNotifier;

            foreach (string id in CallbackIds)
            {
                if (TryGetCallback(id) is ScheduledCallback callback)
                {
                    notifier.CancelNotification(callback.Id);

                    await CancelRemoteInvocationAsync(callback);
                }
            }
        }
Exemplo n.º 4
0
        public override void CancelSilentNotifications()
        {
            UNUserNotificationCenter.Current.GetPendingNotificationRequests(requests =>
            {
                UNUserNotificationNotifier notifier = SensusContext.Current.Notifier as UNUserNotificationNotifier;

                foreach (UNNotificationRequest request in requests)
                {
                    if (TryGetCallback(request.Content?.UserInfo)?.Silent ?? false)
                    {
                        notifier.CancelNotification(request);
                    }
                }
            });
        }
Exemplo n.º 5
0
        protected override async Task ReissueSilentNotificationAsync(string id)
        {
            // the following needs to be done on the main thread
            await SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(async() =>
            {
                UNUserNotificationNotifier notifier = SensusContext.Current.Notifier as UNUserNotificationNotifier;

                UNNotificationRequest request;

                lock (_callbackIdRequest)
                {
                    request = _callbackIdRequest[id];
                }

                await notifier.IssueNotificationAsync(request);
            });
        }