0
votes

As in Android we have Broadcast and in iOS we have NSNotifiactionCenter to send background messages and notifications...

There is something equivalent in Windows Phone 8.1?? I'm looking for documentation about this but I cannot find anything.

Thanks a lot!! Jorge.

1

1 Answers

2
votes

There is no broadcast in WP 8.1, but for this i'm using implementation from Caliburn framework.

https://github.com/Caliburn-Micro/Caliburn.Micro/blob/master/src/Caliburn.Micro/EventAggregator.cs

edit:

or you can implement your own broadcast - I used this in one of my projects

using System;
using System.Collections.Generic;

/* Created by Jan Kobersky - 8/28/2015 6:46:06 PM */
namespace EveryDay.Code.Core
{
    public class EventDispatcher
    {
        private static EventDispatcher _data;
        public static EventDispatcher Dispatcher => _data ?? (_data = new EventDispatcher());

        private readonly List<object> _subscribers = new List<object>();

        private EventDispatcher()
        {

        }

        public void Subscribe(object subscriber)
        {
            if (!_subscribers.Contains(subscriber))
            {
                _subscribers.Add(subscriber);
            }
        }

        public void Unsubscribe(object subscriber)
        {
            if (_subscribers.Contains(subscriber))
            {
                _subscribers.Remove(subscriber);
            }
        }

        public void Dispatch<T>(T message) where T : class
        {
            foreach (var subscriber in _subscribers)
            {
                (subscriber as IHandle<T>)?.Handle(message);
            }
        }
    }

    public interface IHandle<T> where T : class
    {
        void Handle(T message);
    }
}