Ejemplo n.º 1
0
        public static void PushNotificationReceived(string content)
        {
            var settings = ApplicationData.Current.LocalSettings;

            string titleFieldName               = GetFieldName(settings, TITLE_FIELD_NAME_KEY, "title");
            string textFieldName                = GetFieldName(settings, TEXT_FIELD_NAME_KEY, "text");
            string userDataFieldName            = GetFieldName(settings, USER_DATA_FIELD_NAME_KEY, "");
            string notificationProfileFieldName = GetFieldName(settings, NOTIFICATION_PROFILE_FIELD_NAME_KEY, "notification_profile");
            string idFieldName    = GetFieldName(settings, ID_FIELD_NAME_KEY, "id");
            string badgeFieldName = GetFieldName(settings, BADGE_FIELD_NAME_KEY, "badge_number");

            JsonObject json  = JsonValue.Parse(content).GetObject();
            string     title = ExtractStringValue(json, titleFieldName);

            if (title != null)
            {
                title = UrlDecode(title);
            }
            else
            {
                title = string.Format(VALUE_NOT_PRESENT_MESSAGE_FORMAT, titleFieldName);
            }

            string text = ExtractStringValue(json, textFieldName);

            if (text == null)
            {
                // Supporting OneSignal format
                text = ExtractStringValue(json, "alert");
            }
            if (text != null)
            {
                text = UrlDecode(text);
            }
            else
            {
                text = string.Format(VALUE_NOT_PRESENT_MESSAGE_FORMAT, textFieldName);
            }

            int id = ExtractIntValue(json, idFieldName, -1);

            if (id < 0)
            {
                id = NotificationTools.GetNextPushNotificationId();
            }

            string notificationProfile = ExtractStringValue(json, notificationProfileFieldName);

            NotificationTools.PostLocalNotification(title, text, id, GetUserData(json, userDataFieldName), notificationProfile);
        }
Ejemplo n.º 2
0
        //public
        public static void Register()
        {
            string taskName = typeof(PushBackgroundTask).FullName.ToLower();

            if (NotificationTools.IsBackgroundTaskRegistered(taskName))
            {
                return;
            }

            BackgroundTaskBuilder builder = new BackgroundTaskBuilder();

            builder.TaskEntryPoint = typeof(PushBackgroundTask).FullName;
            builder.Name           = taskName;
            builder.SetTrigger(new PushNotificationTrigger());

            builder.Register();
        }
Ejemplo n.º 3
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            RawNotification notification = (RawNotification)taskInstance.TriggerDetails;

            NotificationTools.PushNotificationReceived(notification.Content);
        }
Ejemplo n.º 4
0
 public void Run(IBackgroundTaskInstance taskInstance)
 {
     NotificationTools.Reschedule(false);
 }