1
votes

I've created an APP(Xamarin.forms) in Visual Studio 2017. I want to add wifi connection function into my iOS project (using NEHotspotConfigurationManager) and compile the following code on 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;
}

Even though I can see "Add reference 'Xamarin.iOS.dll'" when I have a right-click on the red words, but it still appears three errors about Foundation, UIKit, and NetworkExtension not being found after I compiled the project.

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?)

I check the 'Xamarin.iOS' in the reference list in iOS project(Modbusbutton3.iOS) with the version 0.0.0.0 enter image description here

However, the reference 'Xamarin.iOS' in the project(Modbusbutton3) is blank. I don't know whether it's related to my problem enter image description here

I found that the reference 'Xamarin.iOS' in the project(Modbusbutton3) showed a red error with "Assembly not found for framework .NET Protable Subset (.NET Framework 4.5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8)" enter image description here

What should I do with this problem?

1
Are you using the latest VS for Mac? Your Xamarin.iOS is not referenced correctly in Visual-Studio for Mac. - Jack Hua

1 Answers

0
votes

The problem with what you are trying to do is that, you need to understand that there is a separation of concerns/abstraction. The Core project is referenced by the Android & iOS projects, but the Android & iOS projects are not referenced by the Core project. Schematically,

Core-->Android & Core-->iOS but Core<-x-Android, Core<-x-iOS

This is by design, and even though you can make it do what you are trying, you shouldn't.

We know that the iOS & Android SDKs are very different. So in order to perform wifi connection functionality (NEHotspotConfigurationManager), you have to perform different functions underneath. And the code that you shared is the correct way of retrieving the path/file name natively ONLY for iOS.

In order to make it work, there's also many other ways of doing this as shown in the official Microsoft docs here.