【问题标题】:Send local broadcast message in Windows Phone 8.1在 Windows Phone 8.1 中发送本地广播消息
【发布时间】:2015-09-21 20:59:44
【问题描述】:

在 Android 中我们有广播,在 iOS 中我们有 NSNotifiactionCenter 来发送后台消息和通知...

Windows Phone 8.1 中有类似的东西?? 我正在寻找有关此的文档,但我找不到任何东西。

非常感谢!! 豪尔赫。

【问题讨论】:

    标签: notifications windows-phone-8.1


    【解决方案1】:

    WP 8.1 中没有广播,但为此我正在使用 Caliburn 框架的实现。

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

    编辑:

    或者您可以实现自己的广播 - 我在我的一个项目中使用了它

    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);
        }
    }
    

    【讨论】:

    • 谢谢!正如你所说,我正在考虑实施我自己的广播,但我认为 WP8.1 会有一些东西可以在后台发送消息......因此我已经发布了这个问题。我错了。
    猜你喜欢
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多