【问题标题】:Xamarin.Forms Error CS0246 'Foundation' could not be foundXamarin.Forms 错误 CS0246 'Foundation' 找不到
【发布时间】:2020-04-23 04:07:44
【问题描述】:

我在 Visual Studio 2017 中创建了一个 APP(Xamarin.forms)。 我想将wifi连接功能添加到我的iOS项目中(使用NEHotspotConfigurationManager)并在Mac上编译以下代码:

bool success = await UIApplication.SharedApplication.OpenUrlAsync(
NSUrl.FromString(UIApplication.OpenSettingsUrlString), options: new UIApplicationOpenUrlOptions());

var config = new NEHotspotConfiguration(ssid, password, isWep: false);
config.JoinOnce = false;
var tcs = new TaskCompletionSource<NSError>();
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(config, err => tcs.SetResult(err));
var error = await tcs.Task;
if (error != null)
{
    var alert = new UIAlertController
    {
        Title = "Error",
        Message = error.Description
    };
    alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
    PresentViewController(alert, true, null);
    return;
}

虽然我在红字上右击可以看到“Add reference 'Xamarin.iOS.dll'”,但是编译后还是出现Foundation, UIKit, and NetworkExtension not found三个错误该项目。

Error CS0246 The type or namespace name 'Foundation' could not be found (are you missing a using directive or an assembly reference?)
Error CS0246 The type or namespace name 'UIKit' could not be found (are you missing a using directive or an assembly reference?)
Error CS0246 The type or namespace name 'NetworkExtension' could not be found (are you missing a using directive or an assembly reference?)

我在版本 0.0.0.0 的 iOS 项目 (Modbusbutton3.iOS) 的参考列表中检查了“Xamarin.iOS” enter image description here

但是,项目 (Modbusbutton3) 中的引用“Xamarin.iOS”为空白。不知道是不是和我的问题有关 enter image description here

我发现项目中的引用“Xamarin.iOS”(Modbusbutton3)显示红色错误 “未找到框架 .NET Protable 子集(.NET Framework 4.5、Windows 8、Windows Phone 8.1、Windows Phone Silverlight 8)的程序集” enter image description here

这个问题我该怎么办?

【问题讨论】:

  • 您使用的是最新的 VS for Mac 吗?在 Visual-Studio for Mac 中未正确引用您的 Xamarin.iOS。

标签: c# xamarin xamarin.forms xamarin.ios visual-studio-mac


【解决方案1】:

您尝试做的问题是,您需要了解关注点/抽象是分离的。 Core 项目被 Android & iOS 项目引用,但 Android & iOS 项目不被 Core 项目引用。示意图,

Core--&gt;Android &amp; Core--&gt;iOS 但是 Core&lt;-x-Android, Core&lt;-x-iOS

这是设计使然,即使你可以让它做你想做的事,你也不应该这样做。

我们知道 iOS 和 Android SDK 非常不同。因此,为了执行 wifi 连接功能(NEHotspotConfigurationManager),您必须在下面执行不同的功能。您共享的代码是仅适用于 iOS 本地检索路径/文件名的正确方法。

为了让它发挥作用,还有很多其他方法可以做到这一点,如官方Microsoft docs here所示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-28
    • 2019-07-14
    • 2019-09-14
    • 2013-10-23
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多