繁体   English   中英

Xamarin 表单本地通知

[英]Xamarin Forms Local Notification

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

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

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

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

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

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

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

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

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

源代码中,这里:

        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 建议的那样。

暂无
暂无

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

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