public static ResultPush Ios(IosMessage iosMessage) { ResultPush resultPush = new ResultPush(); X509Certificate2 certificate = new X509Certificate2(File.ReadAllBytes(GetConfig.Certificate.IOS), GetConfig.Certificate.IOSPassword); var appleCert = File.ReadAllBytes(GetConfig.Certificate.IOS); PushBroker push = Pusher(resultPush); push.RegisterAppleService(new ApplePushChannelSettings(false, certificate)); AppleNotificationPayload appleNotificationPayload = new AppleNotificationPayload(iosMessage.Alert, iosMessage.Badge.Value, iosMessage.Sound.ToString()); var appleNotification = new AppleNotification() .ForDeviceToken(iosMessage.DeviceToken) .WithPayload(appleNotificationPayload); if (iosMessage.Sound.HasValue) { appleNotification.WithSound(iosMessage.Sound.ToString()); } if (iosMessage.Badge.HasValue) { appleNotification.WithBadge(iosMessage.Badge.Value); } push.QueueNotification(appleNotification); return(resultPush); }
private static PushBroker Pusher(ResultPush resultPush) { PushBroker push = new PushBroker(resultPush); push.OnNotificationSent += NotificationSent; push.OnChannelException += ChannelException; push.OnServiceException += ServiceException; push.OnNotificationFailed += NotificationFailed; push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired; push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged; push.OnChannelCreated += ChannelCreated; push.OnChannelDestroyed += ChannelDestroyed; return(push); }
public static ResultPush Android(AndroidMessage androidMessage) { ResultPush resultPush = new ResultPush(); if (androidMessage != null) { PushBroker push = Pusher(resultPush); push.RegisterGcmService(new GcmPushChannelSettings(GetConfig.Key.Android)); var jsonObject = JsonConvert.SerializeObject(androidMessage, SerializerSettings()); push.QueueNotification(new GcmNotification() .ForDeviceRegistrationId(androidMessage.DeviceTokens) .WithJson(jsonObject)); } return(resultPush); }
public static void NotificationFailed(object sender, INotification notification, Exception notificationFailureException, ResultPush resultPush) { resultPush.CallbackFailed(sender, notification, notificationFailureException); Console.WriteLine("Failure: " + sender + " -> " + notificationFailureException.Message + " -> " + notification); }
public static void NotificationSent(object sender, INotification notification, ResultPush resultPush) { resultPush.CallbackSent(sender, notification); Console.WriteLine("Sent: " + sender + " -> " + notification); }
public void QueueNotification(INotification notification, ResultPush resultPush) { this.resultPush = resultPush; QueueNotification(notification, false); }
public PushBroker(ResultPush resultPush) { serviceRegistrations = new List <ServiceRegistration> (); this.resultPush = resultPush; }