Hi,
Recieved the NEHotspotHelper entitlement today and have been experimenting with it for almost 6 hours now. Got most of the parts working including auto-join for psk networks using passwords from the app. However when the network is a captive one, on which window should I present my custom view to interact with the captive portal? I tried it with UIApplication.sharedApplication as AppDelegate and used its window, but the app isn't pushed to the foreground. Is there a window on the Settings app on which I can present my UIVIewController because I've seen an app do this.Here is the snippet of my code.
switch command.commandType { case .FilterScanList: var networkListCanHandle = [NEHotspotNetwork]() guard let networkList = command.networkList else { print("No networks in the filter scan list") return } for network in networkList { network.setConfidence(.High) networkListCanHandle.append(network) } let response = command.createResponse(.Success) response.setNetworkList(networkListCanHandle) response.deliver() case .Evaluate: guard let network = command.network else { print("Network not present") return } if network.SSID == "My Captive Portal" { network.setConfidence(.High) let response = command.createResponse(.Success) response.setNetwork(network) response.deliver() } case .Authenticate: guard let network = command.network else { print("Network not present") return } if network.SSID == "My Captive Portal" { network.setConfidence(.High) let response = command.createResponse(.UIRequired) response.setNetwork(network) response.deliver() } case .PresentUI: dispatch_async(dispatch_get_main_queue(), { let customController: UIAlertController = UIAlertController(title: "Captive Login", message: "Let us handle the login", preferredStyle: .Alert) // What should be the window here?? self.window?.rootViewController?.presentViewController(customController, animated: true, completion: nil) }) case .Maintain: break case .Logoff: break case .None: break }
However when the network is a captive one, on which window should I present my custom view to interact with the captive portal?
The hotspot system will never yank your app to the front; that’s not the way iOS works (-: The standard approach here is to use a local notification to tell the user that you need attention. If they respond to the notification, your app comes to the front and you can present UI in the normal way.
This process is pretty well described in the comments at the top of
<NetworkExtension/NEHotspotHelper.h>
.
In the Authenticating state, if the helper determines that it requires user interaction to proceed, the helper first arranges to alert the user via a UserLocalNotification, then returns a result of UIRequired. The state machine enters the PresentingUI state.
In the PresentingUI state, the helper is given a command of type PresentUI. The application is not kept running in the background in this state: PresentingUI relies on the user bringing the application to the foreground manually or via the UILocalNotification. Once the application has the required information, it returns Success to enter the Authenticated state.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
WWDC runs Mon, 13 Jun through to Fri, 17 Jun. During that time all of DTS will be at the conference, helping folks out face-to-face. http://developer.apple.com/wwdc/