public Stream SendMessage(Stream messageBody) { try { var doc = new XmlDocument(); doc.Load(messageBody); var msg = new PushMessage(doc, _solution.Name); var push = new PushBroker(); string result = ""; if (msg.HasGcmRecipients) { push.RegisterGcmService(new GcmPushChannelSettings(AndroidServerKey)); string json = "{\"alert\":\"" + msg.Data + "\"}"; foreach (string token in msg.GcmTokens) { push.QueueNotification(new GcmNotification().ForDeviceRegistrationId(token).WithJson(json)); } result += "Android: ok; "; } if (msg.HasApnsRecipients) { var appleCert = Convert.FromBase64String(IosProductionCertificate); push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "h2o+c2h5oh")); foreach (string token in msg.ApnsTokens) { push.QueueNotification(new AppleNotification() .ForDeviceToken(token) .WithAlert(msg.Data) .WithSound("sound.caf")); } result += "IOS: ok; "; } return(Common.Utils.MakeTextAnswer(result)); } catch (Exception e) { return(Common.Utils.MakeExceptionAnswer(e)); } }
public Stream SendMessage(Stream messageBody) { try { var doc = new XmlDocument(); doc.Load(messageBody); var msg = new PushMessage(doc, _solution.Name); var push = new PushBroker(); string result = ""; if (msg.HasGcmRecipients) { push.RegisterGcmService(new GcmPushChannelSettings(AndroidServerKey)); string json = "{\"alert\":\"" + msg.Data + "\"}"; foreach (string token in msg.GcmTokens) push.QueueNotification(new GcmNotification().ForDeviceRegistrationId(token).WithJson(json)); result += "Android: ok; "; } if (msg.HasApnsRecipients) { var appleCert = Convert.FromBase64String(IosProductionCertificate); push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "h2o+c2h5oh")); foreach (string token in msg.ApnsTokens) { push.QueueNotification(new AppleNotification() .ForDeviceToken(token) .WithAlert(msg.Data) .WithSound("sound.caf")); } result += "IOS: ok; "; } return Common.Utils.MakeTextAnswer(result); } catch (Exception e) { return Common.Utils.MakeExceptionAnswer(e); } }