public IHttpActionResult NotifyHub(PushMessage msg) { try { var connStr = "Endpoint=sb://azdevelop.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=XquAb+oTzm4huD0htIMeV+mCG/o8ekm6958RTPvYCpQ="; var hubName = "referenceguide"; hub = NotificationHubClient.CreateClientFromConnectionString(connStr, hubName); NotificationOutcome outcome = null; if (msg.DeviceType == 1) { outcome = SendAPNS(msg); } else { outcome = SendGCM(msg); } msg.Success = outcome.State == NotificationOutcomeState.Completed ? true : false; } catch (Exception ex) { var x = ex.Message; } return(Ok(msg)); }
private NotificationOutcome SendGCM(PushMessage msg) { var obj = new GCMMessage.RootObject(); obj.data.Add("title", msg.Title); obj.data.Add("message", msg.Message); var json = JsonConvert.SerializeObject(obj); return(hub.SendGcmNativeNotificationAsync(json, msg.Tag).Result); }
private NotificationOutcome SendAPNS(PushMessage msg) { var obj = new APNS.RootObject(); obj.Content.Alert.Add("title", "Special Alert"); obj.Content.Alert.Add("body", "There is a sale at Walmart"); obj.Content.Badge = 1; obj.Content.ContentAvailable = 1; var json = JsonConvert.SerializeObject(obj); return(hub.SendAppleNativeNotificationAsync(json, msg.Tag).Result); }