0

I am implementing an APP through Xamarin that will force the iPhone to connect to a specific SSID.

Here is my code

var config = new NEHotspotConfiguration(SSID, Password, isWep: false)
config.JoinOnce = true;
var tcs = new TaskCompletionSource<NSError>();
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(config, err => tcs.SetResult(err));

There are two test result

Assume the target SSID I want to connect called "SSID-A"

  1. I delete the record of "SSID-A" in the iOS system page. Then deploy this APP to the phone. I give the correct SSID/Password into the code above. The system popup a message "Unable to join". Failed to connect to this SSID.

  2. I go to iOS system page. Manually connect to "SSID-A". Check the connection is done. Then I connect to mobile phone to other SSID. And go back to the APP. This time. It works.

Why there is a different at here?

What can I do to look more into this problem to solve this?

Thanks!

CC.Wang
  • 111
  • 1
  • 12
  • 1
    Hi, do you have a try with `config.JoinOnce = false;` or not adding this line to check whether it works? – Junior Jiang Oct 21 '20 at 06:40
  • And you also could have a check with [applyConfiguration:completionHandler:](https://developer.apple.com/documentation/networkextension/nehotspotconfigurationmanager/2866649-applyconfiguration?language=objc), whehter has the same situation as that said. *This method attempts to join the network only if it's found nearby. Also, because of the noticeable delay that the Hotspot 2.0 discovery mechanism may incur, the method doesn't attempt to join Hotspot 2.0 networks. * – Junior Jiang Oct 21 '20 at 06:46
  • @JuniorJiang-MSFT `config.JoinOnce = false;` This works! Thank you for your help! But can you explain why this could affect this problem? – CC.Wang Oct 22 '20 at 01:58
  • 1
    Hi, as the second comment's said, there will be some delays to find the network and connect it. Therefore, Join once can not mark sure it works. In addition, it seems a bug in iOS 13 from Apple. You could have a look at [this discussion](https://stackoverflow.com/questions/58029300/ios-13-using-the-new-nehotspotconfiguration-initssidprefix-string-does-not-s). If have solved this, would you mind I edit this as an answer? – Junior Jiang Oct 22 '20 at 02:18
  • Of course. Thank you! – CC.Wang Oct 22 '20 at 06:19
  • Okey, I have updated it in answer. Please do not forget to accept it as answer( click the ✔ in the upper left corner of this answer), it will help others who have similar issue. – Junior Jiang Oct 22 '20 at 08:31

2 Answers2

1

From applyConfiguration:completionHandler: of apple document, we could see the dicsussion that:

This method attempts to join the network only if it's found nearby. Also, because of the noticeable delay that the Hotspot 2.0 discovery mechanism may incur, the method doesn't attempt to join Hotspot 2.0 networks.

Therefore, Join once seems can not mark sure it works.We could have a try with remove this line, or set false as follows:

config.joinOnce = false;

In addition, it seems a bug in iOS 13 from Apple. You could have a look at this discussion.

Hardik Thakkar
  • 15,269
  • 2
  • 94
  • 81
Junior Jiang
  • 12,430
  • 1
  • 10
  • 30
0

In case it helps someone one day I had an issue suddenly start where my device was unable to join a network which has previously been working fine.

To test an error condition I tried connecting to a secure network without adding the passphase to the NEHotspotConfiguration. This attempt to join failed but then subsequently after putting the passphase back in the device wouldn't even display the join request dialog and would just fail with an 'Unable to join' error.

I eventually tried another test phone and this worked just fine so it seemed to be an issue on the device itself. I tried resetting my device's network settings but this made no difference.

The fix was to go into the device's wifi setting, join the network manually, return to my app, attempt to join, disconnect from the network in the device settings, and then forget the network. After that it worked fine on every subsequent attempt.

Leon
  • 3,614
  • 1
  • 33
  • 46