示例#1
0
        public void Send(NotificationPayload notification, IDevice device)
        {
            // Configuration
            var config = new GcmConfiguration(senderId, authToken, packageName);

            // Make the broker use Firebase
            config.GcmUrl = "https://fcm.googleapis.com/fcm/send";

            // Create a new broker
            var gcmBroker = new GcmServiceBroker(config);

            // Wire up events
            gcmBroker.OnNotificationFailed    += onFailure;
            gcmBroker.OnNotificationSucceeded += onSuccess;

            var payload = new AndroidNotification(notification);

            // Start the broker
            gcmBroker.Start();
            // Queue a notification to send
            gcmBroker.QueueNotification(new GcmNotification
            {
                To   = device.Token,
                Data = JObject.FromObject(payload)
            });

            // Stop the broker, wait for it to finish
            // This isn't done after every message, but after you're
            // done with the broker
            gcmBroker.Stop();
        }
示例#2
0
        public void Send(NotificationPayload notification, IEnumerable <IDevice> devices)
        {
            // Configuration
            var config = new GcmConfiguration(senderId, authToken, packageName);

            // Make the broker use Firebase
            config.GcmUrl = "https://fcm.googleapis.com/fcm/send";

            // Create a new broker
            var gcmBroker = new GcmServiceBroker(config);

            // Wire up events
            gcmBroker.OnNotificationFailed    += onFailure;
            gcmBroker.OnNotificationSucceeded += onSuccess;

            var payload = new AndroidNotification(notification);

            // Make chuncks of 1000 devices that is the max quote supported
            var chuncks = devices.ToList().ChunkBy(1000);

            // Start the broker
            gcmBroker.Start();
            foreach (var chunck in chuncks)
            {
                // Queue a notification to send
                gcmBroker.QueueNotification(new GcmNotification
                {
                    RegistrationIds = devices.Select(d => d.Token).ToList <string>(),
                    Data            = JObject.FromObject(payload)
                });
            }

            // Stop the broker, wait for it to finish
            // This isn't done after every message, but after you're
            // done with the broker
            gcmBroker.Stop();
        }