コード例 #1
0
        private FcmSharp.Requests.Notification ConvertNotification(Notification source)
        {
            if (source == null)
            {
                return(null);
            }

            return(new FcmSharp.Requests.Notification
            {
                Title = source.Title,
                Body = source.Body
            });
        }
コード例 #2
0
        public async Task SendNotificationAsync(ApplicationUser user, Notification notification, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var context = factory.Create())
            {
                var tokens = await context.DbSet <UserRegistration>()
                             .Where(x => x.DeactivationDate == null)
                             .Select(x => x.RegistrationToken)
                             .ToListAsync(cancellationToken);

                var tasks = tokens.Select(x => SendNotificationAsync(x, notification, cancellationToken));

                await Task.WhenAll(tasks);
            }
        }
コード例 #3
0
        private async Task SendNotificationAsync(string token, Notification notification, CancellationToken cancellationToken)
        {
            var message = new FcmMessage
            {
                ValidateOnly = false,
                Message      = new Message
                {
                    Token        = token,
                    Notification = ConvertNotification(notification)
                }
            };

            await client.SendAsync(message, cancellationToken);
        }
コード例 #4
0
        public async Task SendNotificationAsync(Topic topic, Notification notification, CancellationToken cancellationToken = default(CancellationToken))
        {
            var message = new FcmMessage
            {
                ValidateOnly = false,
                Message      = new Message
                {
                    Topic        = topic.Name,
                    Notification = ConvertNotification(notification)
                }
            };

            await client.SendAsync(message, cancellationToken);
        }