1

我正在 Xamarin Forms 中开发一个应用程序,它连接到一些没有可用 Internet 连接的 IoT 设备。

IoT 设备公开了一个免费的 WIFI 热点,应用程序连接到该热点。在 iOS 端,为了执行连接,我使用对象的NEHotspotConfigurationManager.SharedManager.ApplyConfiguration方法NEHotspotConfiguration。这是我用来执行连接的代码的一部分:

NEHotspotConfiguration configuration = new NEHotspotConfiguration(ssid);
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(configuration, (NSError error) =>
{
    if (error != null)
    {
         if (error.LocalizedDescription == "already associated.")
         {
             return true;
         }
         else
         {
             return false;
         }
    }
    else
    {
         return true;
    }
});

一切正常,应用程序成功连接了物联网设备,一旦建立连接,我就可以与之交互。但有时会显示提示,通知Wi-Fi 网络“wifi 名称”似乎未连接到互联网。您想暂时使用蜂窝数据吗?

有什么办法可以避免显示这个提示。我读到在NEHotspotConfiguration对象中将 joinOnce 设置为 true 可以解决问题,但是,如果使用此标志 = true,一旦将应用程序置于后台,与 IoT 设备的连接就会中断。

是否可以离开joinOnce设置false并避免上述提示?

4

0 回答 0