Esempio n. 1
0
        public APNSNotification(APNSMessage message, bool priority)
        {
            Dictionary <string, Object> aps = new Dictionary <string, Object>();

            aps.Add("aps", message.getDictionary());

            string json = JsonConvert.SerializeObject(aps);

            messageSize = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(Convert.ToInt16(json.Length)));
            messageData = Encoding.UTF8.GetBytes(json);

            if (priority)
            {
                priorityData = new byte[1] {
                    0x10
                };
            }
            else
            {
                priorityData = new byte[1] {
                    0x05
                };
            }

            // ID + Token Size + Token + Message ID + Message Size + Message Data Length
            int commandSize = 1 + 2 + 32 + 1 + messageSize.Length + messageData.Length;

            commandBytes = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(commandSize));
        }
Esempio n. 2
0
		public APNSNotification(APNSMessage message, bool priority)
		{
			Dictionary<string, Object> aps = new Dictionary<string, Object>();
			aps.Add("aps", message.getDictionary());

			string json = JsonConvert.SerializeObject(aps);

			messageSize = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(Convert.ToInt16(json.Length)));
			messageData = Encoding.UTF8.GetBytes(json);

			if (priority) {
				priorityData = new byte[1] { 0x10 };
			} else {
				priorityData = new byte[1] { 0x05 };
			}

			// ID + Token Size + Token + Message ID + Message Size + Message Data Length
			int commandSize = 1 + 2 + 32 + 1 + messageSize.Length + messageData.Length;

			commandBytes = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(commandSize));
		}
Esempio n. 3
0
        public static void sendNotification(List<MobileAppPushRegistration> registrations, string title, string content)
        {
            APNSConnection connection = new APNSConnection();
            connection.open();

            APNSAlert alert = new APNSAlert("New Notification", "You have a notification!");

            APNSMessage message = new APNSMessage();
            message.addAlert(alert);
            message.addSound("default");
            message.addCommand(3);

            APNSNotification notification = new APNSNotification(message, true);

            foreach (MobileAppPushRegistration registration in registrations)
            {
                notification.setDeviceToken(registration.RegistrationId);
                notification.sendViaConnection(connection);
            }

            connection.close();
        }
Esempio n. 4
0
        public static void sendNotification(List <MobileAppPushRegistration> registrations, string title, string content)
        {
            APNSConnection connection = new APNSConnection();

            connection.open();

            APNSAlert alert = new APNSAlert("New Notification", "You have a notification!");

            APNSMessage message = new APNSMessage();

            message.addAlert(alert);
            message.addSound("default");
            message.addCommand(3);

            APNSNotification notification = new APNSNotification(message, true);

            foreach (MobileAppPushRegistration registration in registrations)
            {
                notification.setDeviceToken(registration.RegistrationId);
                notification.sendViaConnection(connection);
            }

            connection.close();
        }