Xamarin表示本地通知

时间:2018-02-04 03:42:01

标签: android xamarin.forms notifications localnotification

我是xamarin表单的新手,我想为跨平台制作本地通知。我使用edsnider的一个插件调用Xamarin的本地通知插件(Link - https://github.com/edsnider/LocalNotificationsPlugin)并按照文档要求我的操作进行操作。

我创建一个按钮并使用此代码作为其功能。想法是在单击按钮时收到通知

void Notify()
    {
        CrossLocalNotifications.Current.Show("Alert", "People spot", 10);
    }

当我按下Android设备中的按钮时出现此错误。

  

System.NotImplementedException:方法或操作不是   实现。

希望尽快解决这个问题。谢谢

2 个答案:

答案 0 :(得分:0)

Xamarin插件实现通常特定于平台的功能。因此,您必须在所有项目中安装插件 - 所有平台项目和您的PCL。你得到的错误似乎是插件未正确安装在其中一个项目中。

如果您已将其安装到所有项目中,请尝试从所有项目中卸载它,清理解决方案并再次从NuGet安装。

另请注意,尚未支持macOS上的通知。

答案 1 :(得分:0)

source codes,这里:

        private static ILocalNotifications CreateLocalNotificationsImplementation()
        {
#if NETSTANDARD1_0
            return null;
#else
            return new LocalNotificationsImplementation();
#endif
        }

如果您的.NET Standard为1.0,则会返回null,然后Currentthrow NotImplementedInReferenceAssembly();,因此您获得NotImplementedException

请在PCl的属性文件中查看.Net Framework的版本。

如果是1.0,则需要更改它。

如果不是1.0,则异常意味着您的Android平台上没有LocalNotificationsImplementation实例,就像@Martin Zikmund建议的那样。