在发布模式后台中未检测到网络更改状态 - Xamarin.iOS

发布于 2025-01-09 02:26:56 字数 744 浏览 3 评论 0原文

在我的应用程序中,我使用 Xamarin.Essentials 来检测后台和网络中的网络变化。基于网络可用性的火灾通知。该代码在设备上完美运行调试期间的模拟器。但是,Xamarin.Essentials 无法检测发布模式下的连接更改,尤其是在后台。当应用程序重新进入应用程序时(当应用程序变为前台时),事件会被触发

以下是我使用的代码

    CrossConnectivity.Current.ConnectivityChanged += Current_ConnectivityChanged;
    private void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)

    {
                if (_networkService.IsConnected())
                {
                    ShowBannerNotificaiton("Internet", "Available", "data1");
                }
                else
                {
                    ShowBannerNotificaiton("Internet", "Not Available", "data2");                     
                }
        }

欣赏给出的解决方案

In my application, I have used Xamarin.Essentials to detect network changes in background & fire notifications based on network availability. The code works perfectly on the device & simulator during Debug. However, the Xamarin.Essentials fail to detect connectivity changes in Release mode, especially in the background. The events get triggered when the application reenters into the application (when application becomes ro foreground)

Following is the code I have used

    CrossConnectivity.Current.ConnectivityChanged += Current_ConnectivityChanged;
    private void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)

    {
                if (_networkService.IsConnected())
                {
                    ShowBannerNotificaiton("Internet", "Available", "data1");
                }
                else
                {
                    ShowBannerNotificaiton("Internet", "Not Available", "data2");                     
                }
        }

Appreciate the solution given

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文