public Notification ToNotification() { var notification = new AppleNotification() .ForDeviceToken(Token) .WithContentAvailable(1) .WithAlert(Body) .WithSound(Sound) .WithBadge(Badge) .WithCategory(Category); foreach (var item in CustomItems) { notification.WithCustomItem(item.Key, item.Value); } return notification; }
private void EnqueueApnsNotification(Device device, PushNotification notification) { var config = PushServiceConfiguration.GetSection(); string message = notification.Message; if (message != null && message.Length > config.Apns.MaxMessageLength) message = notification.ShortMessage ?? notification.Message; if (message != null && message.Length > config.Apns.MaxMessageLength) { _log.WarnFormat("message is larger than maximum allowed length of {0}", config.Apns.MaxMessageLength); return; } var apnsNotification = new AppleNotification() .ForDeviceToken(device.Token) .WithAlert(message) .WithBadge(device.Badge) .WithCustomItem("regid", device.RegistrationID); if (notification.Module != PushModule.Unknown && notification.Item != null) { var itemType = notification.Item.Type; var itemId = notification.Item.ID; if (notification.Item.Type == PushItemType.Subtask && notification.ParentItem != null) { itemType = notification.ParentItem.Type; itemId = notification.ParentItem.ID; } apnsNotification.WithCustomItem("itemid", itemId); apnsNotification.WithCustomItem("itemtype", itemType.ToString().ToLower()); } if (config.IsDebug || !config.Apns.ElementInformation.IsPresent) { _log.DebugFormat("notification ({0}) prevented from sending to device {1}", apnsNotification, device.ID); return; } PushBrokerProvider.Instance.QueueNotification(apnsNotification); }