コード例 #1
0
        private static void SendApnsNotification(string MessageLocKey, object[] MessageLocArgs, string Sound, string ActionType, Dictionary <string, object> CustomItems)
        {
            List <AppUserTokenUI> tokens = AppUserTokenUI.GetAllAPNSAppUserTokenUI();

            NotificationAlert alert = new NotificationAlert();

            alert.LocalizedKey = MessageLocKey;
            if (MessageLocArgs != null)
            {
                alert.LocalizedArgs.AddRange(MessageLocArgs);
            }

            Dictionary <string, object[]> customItems = null;

            if (ActionType != null)
            {
                customItems = new Dictionary <string, object[]>();
                customItems[@"app-action"] = new object[] { ActionType };
            }
            if (CustomItems != null)
            {
                foreach (string key in CustomItems.Keys)
                {
                    if (CustomItems[key] == null)
                    {
                        continue;
                    }
                    if (customItems == null)
                    {
                        customItems = new Dictionary <string, object[]>();
                    }
                    customItems[key] = new object[] { CustomItems[key] };
                }
            }

            foreach (AppUserTokenUI token in tokens)
            {
                NotificationService service = APNSService.SharedInstance;
                service.SendMessage(token.Token,
                                    alert,
                                    token.UnreadNotificationCount,
                                    (Sound == null || Sound.Length == 0) ? @"default" : Sound,
                                    customItems,
                                    delegate()
                {
                    Query qry = Query.New <AppUserAPNSToken>().Delete()
                                .Where(AppUserAPNSToken.Columns.Token, token);
                });
            }
        }
コード例 #2
0
        public JsonResult SendMedicalAlert(NotificationAlert oNotificationAlert)
        {
            Api API = new Api();

            oNotificationAlert.nodeId       = ViewBag.USER.NodeId;
            oNotificationAlert.systemUserId = ViewBag.USER.SystemUserId;
            Dictionary <string, string> arg = new Dictionary <string, string>()
            {
                { "String1", JsonConvert.SerializeObject(oNotificationAlert) },
            };
            var result = API.Post <string>("Notification/SendMedicalAlert", arg);

            return(new JsonResult {
                Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #3
0
        private static void SendApnsNotification(Int64 SupplierId, string MessageLocKey, object[] MessageLocArgs, Int32 Badge, string Sound, string ActionType, Dictionary <string, object> CustomItems)
        {
            List <string> tokens = new List <string>();

            using (ConnectorBase conn = ConnectorBase.NewInstance())
            {
                Query qry = Query.New <AppSupplierAPNSToken>()
                            .Select(AppSupplierAPNSToken.Columns.Token)
                            .Where(AppSupplierAPNSToken.Columns.SupplierId, SupplierId);

                using (DataReaderBase reader = qry.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tokens.Add(reader.GetString(0));
                    }
                }
            }

            NotificationAlert alert = new NotificationAlert();

            alert.LocalizedKey = MessageLocKey;
            if (MessageLocArgs != null)
            {
                alert.LocalizedArgs.AddRange(MessageLocArgs);
            }

            Dictionary <string, object[]> customItems = null;

            if (ActionType != null)
            {
                customItems = new Dictionary <string, object[]>();
                customItems[@"app-action"] = new object[] { ActionType };
            }
            if (CustomItems != null)
            {
                foreach (string key in CustomItems.Keys)
                {
                    if (CustomItems[key] == null)
                    {
                        continue;
                    }
                    if (customItems == null)
                    {
                        customItems = new Dictionary <string, object[]>();
                    }
                    customItems[key] = new object[] { CustomItems[key] };
                }
            }

            foreach (string token in tokens)
            {
                NotificationService service = APNSServiceSupplier.SharedInstance;
                service.SendMessage(token,
                                    alert,
                                    Badge,
                                    (Sound == null || Sound.Length == 0) ? @"default" : Sound,
                                    customItems,
                                    delegate()
                {
                    Query qry = Query.New <AppSupplierAPNSToken>().Delete()
                                .Where(AppSupplierAPNSToken.Columns.Token, token);
                });
            }
        }