我在Visual Studio2017中创建了一个应用程序(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'“,但它仍然显示三个错误,即在我编译项目后找不到基础、UIKit和NetworkExtension。
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版本的enter image description here检查iOS项目(Modbusbutton3.iOS)中引用列表中的'Xamarin.iOS‘
但是,项目(Modbusbutton3)中的引用'Xamarin.iOS‘为空。我不知道这是否与我的enter image description here问题有关
我发现项目(Modbusbutton3)中的引用'Xamarin.iOS‘显示红色错误"Assembly not found for framework .NET Protable Subset (.NET Framework4.5,Windows8,Windows phone8.1,Windows Phone Silverlight8)“enter image description here
我应该如何处理这个问题?
发布于 2020-04-25 07:26:40
你正在尝试做的事情的问题是,你需要理解关注点/抽象的分离。核心项目被Android & iOS项目引用,但是Android & iOS项目没有被核心项目引用。从原理上讲,
Core-->Android & Core-->iOS而不是Core<-x-Android, Core<-x-iOS
这是设计出来的,即使你可以让它做你正在尝试的事情,你也不应该做。
我们知道iOS和Android SDK有很大的不同。因此,为了执行wifi连接功能(NEHotspotConfigurationManager),您必须在底层执行不同的功能。您共享的代码是仅为iOS本机检索路径/文件名的正确方式。
为了让它工作,还有许多其他的方法,如官方Microsoft docs here中所示。
https://stackoverflow.com/questions/61379215
复制相似问题