簡體   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