简体   繁体   English

Xamarin 表单本地通知

[英]Xamarin Forms Local Notification

i am new to xamarin form and i want to make local notification for cross platform.我是 xamarin 表单的新手,我想为跨平台进行本地通知。 I use a plugin call Local Notifications Plugin for Xamarin by edsnider ( Link - https://github.com/edsnider/LocalNotificationsPlugin ) and follow as what the documentation ask me to do.我使用 edsnider 的 Xamarin 插件调用本地通知插件(链接 - https://github.com/edsnider/LocalNotificationsPlugin )并按照文档要求我做的操作。

I create a button and use this code as it's function.我创建了一个按钮并使用此代码作为它的功能。 The idea is to get a notification when the button is clicked这个想法是在单击按钮时收到通知

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

and i get this error when i press on the button in my android device.当我按下 Android 设备中的按钮时,出现此错误。

System.NotImplementedException: The method or operation is not implemented. System.NotImplementedException:未实现方法或操作。

Hope to solve this matter soon.希望尽快解决这个问题。 Thank you谢谢

Xamarin Plugins implement functionality that is usually platform specific. Xamarin 插件实现通常特定于平台的功能。 Because of that you have to install the plugin in all your projects - all platform projects and your PCL.因此,您必须在所有项目中安装该插件——所有平台项目和您的 PCL。 The error you are gettng seems that the plugin is not properly installed in one of the projects.您收到的错误似乎是该插件未正确安装在其中一个项目中。

If you have installed it into all your projects, please try to uninstall it from all projects, clean your solution and install from NuGet again.如果您已将其安装到所有项目中,请尝试从所有项目中卸载它,清理您的解决方案并再次从 NuGet 安装。

Also note that notifications on macOS are not yet supported.另请注意,尚不支持 macOS 上的通知。

In the source codes , here:源代码中,这里:

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

If your .NET Standard is 1.0, it will return null , and then Current will throw NotImplementedInReferenceAssembly();如果您的.NET Standard是 1.0,它将返回null ,然后Currentthrow NotImplementedInReferenceAssembly(); , so you get NotImplementedException . ,所以你得到NotImplementedException

Please check your the version of .Net Framework in your PCl's Properties file.请在您的 PCl 的属性文件中检查您的 .Net Framework 版本。

If it is 1.0, you need change it.如果是 1.0,则需要更改它。

If it is not 1.0, the exception means that there is no LocalNotificationsImplementation instance on your Android platform, do like @Martin Zikmund has suggested.如果它不是 1.0,则异常意味着您的 Android 平台上没有LocalNotificationsImplementation实例,就像@Martin Zikmund 建议的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM