Forum Xamarin.iOS

NEHotspotHelper.Register always returns false, never runs. VS for Mac breaks entitlements.

ChrisLamont.3643ChrisLamont.3643 USUniversity ✭✭

I am unable to get NEHotspotHelper.Register to ever work, regardless of distribution method (adhoc, store, or debug). Below is all the sample code and configuration needed to reproduce (beside you needing to get NetworkExtension entitlement enabled, which I have). All the code is located in AppDelegate.cs

First, I noticed that VisualStudio for Mac doesn't retain the setting below, and had to compile on Xamarin (stable branch.) The compiled info.plist has this entry present

<key>UIBackgroundModes</key>
<array>
    <string>remote-notification</string>
    <string>network-authentication</string>
</array>

Here is the archived-expanded-entitlements.xcent, located in the compiled output.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.networking.networkextension</key>
    <array>
        <string>app-proxy-provider</string>
        <string>content-filter-provider</string>
        <string>packet-tunnel-provider</string>
    </array>
</dict>
</plist>

This is my code. Is this delegate perhaps a weak reference and getting GC'd prior to being run?

  public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());

            NetworkExtension.NEHotspotHelperOptions netOpts = new NetworkExtension.NEHotspotHelperOptions();
            //  should be no longer than 15 characters
            netOpts.DisplayName = new NSString("VIPCard network");

            DispatchQueue queue = new DispatchQueue("VIPCard", false);

            bool isAvail = NetworkExtension.NEHotspotHelper.Register(netOpts, queue,
                                                                     new NetworkExtension.NEHotspotHelperHandler(
                                                                         (NetworkExtension.NEHotspotHelperCommand cmd) =>
            {

                Console.WriteLine(cmd.CommandType);
                System.Diagnostics.Debug.WriteLine(cmd.CommandType);

                List<NetworkExtension.NEHotspotNetwork> hotspotList = new List<NetworkExtension.NEHotspotNetwork>();
                    if (cmd.CommandType == NetworkExtension.NEHotspotHelperCommandType.Evaluate || cmd.CommandType == NetworkExtension.NEHotspotHelperCommandType.FilterScanList)
                    {
                        foreach (NetworkExtension.NEHotspotNetwork network in cmd.NetworkList)
                        {


                            network.SetConfidence(NetworkExtension.NEHotspotHelperConfidence.High);
                                network.SetPassword("pkgPassword");
                                hotspotList.Add(network);

                        }
                    }

                NetworkExtension.NEHotspotHelperResponse response = cmd.CreateResponse(NetworkExtension.NEHotspotHelperResult.Success);
                response.SetNetworkList(hotspotList.ToArray());
                response.Deliver();
            }  ));

            Console.WriteLine("Hotspot helper status: " + isAvail);

            return base.FinishedLaunching(app, options);

        }

Files are attached... I would include mobileprovision, but that file extension isn't permitted, and I can't figure out a way to attach a .BIN file

Posts

  • ChrisLamont.3643ChrisLamont.3643 USUniversity ✭✭
    edited May 2017

    Got it working. Needed this in entitlements. VS for Mac is still messing up entitlements, so I'm using Xamarin Studio for now

      <key>com.apple.developer.networking.HotspotHelper</key> <true/> 
    
Sign In or Register to comment.