- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 NEHotspotHelper 并尝试注册但没有收到回电。首先,
然后添加以下代码,
let options: [String: NSObject] = [kNEHotspotHelperOptionDisplayName : "ABC" as NSObject]
let queue: DispatchQueue = DispatchQueue(label: "com.ABC", attributes: DispatchQueue.Attributes.concurrent)
NSLog("Started wifi scanning.")
NEHotspotHelper.register(options: options, queue: queue) { (cmd: NEHotspotHelperCommand) in
NSLog("Received command: \(cmd.commandType.rawValue)")
if cmd.commandType == NEHotspotHelperCommandType.filterScanList {
//Get all available hotspots
let list: [NEHotspotNetwork] = cmd.networkList!
//Figure out the hotspot you wish to connect to
print(list)
} else if cmd.commandType == NEHotspotHelperCommandType.evaluate {
if let network = cmd.network {
//Set high confidence for the network
network.setConfidence(NEHotspotHelperConfidence.high)
let response = cmd.createResponse(NEHotspotHelperResult.success)
response.setNetwork(network)
response.deliver() //Respond back
}
} else if cmd.commandType == NEHotspotHelperCommandType.authenticate {
//Perform custom authentication and respond back with success
// if all is OK
let response = cmd.createResponse(NEHotspotHelperResult.success)
response.deliver() //Respond back
}
}
如果我遗漏了任何步骤,请告诉我。
最佳答案
您应该检查 register()
函数的结果。如果它返回 false
,则可能是某些配置不正确。请参阅下面的完整配置说明列表。
此外,在您提供的屏幕截图中,您已为热点配置 启用了权利,但您调用的 API 是针对热点助手 的。这两个功能需要非常不同的权利。您需要确保为 Hotspot Helper 配置所有内容以调用该 API。同样,请参阅下面的完整详细信息。有关这些名称相似的 API 的区别的更多详细信息,请参阅 Hotspot Helper vs. Hotspot Configuration。
申请网络扩展授权。
这需要在 Apple's website here 完成。
修改您的配置文件。
转到 http://developer.apple.com 。点击您个人资料附近的编辑
。在显示 Entitlements
的底部,选择包含 Network Extension entitlement 的那个。
更新您应用的授权文件。
The application must set
com.apple.developer.networking.HotspotHelper
as one of its entitlements. The value of the entitlement is a boolean set to true.
添加背景模式
The application's
Info.plist
must include aUIBackgroundModes
array containingnetwork-authentication
.
请注意,与转换为人类可读字符串的所有其他后台模式不同,此模式将保留为 network-authentication
。
调用NEHotspotHelper.register()
函数。
This method should be called once when the application starts up. Invoking it again will have no effect and result in false being returned.
您应该确保函数返回 true
。否则,上述步骤之一可能未正确配置。
了解何时调用此回调。
从文档中,并不完全清楚调用此回调的确切时间。例如,人们可能会假设 NEHotspotHelper 可用于监视网络连接。但是,回调将(仅?)在用户导航到“设置”应用并转到 Wi-Fi 页面时调用。
由于只有当用户在“设置”应用中时才会调用您的回调,因此您应该附加到调试器并使用 print()
。
let targetSsid = "SFO WiFi"
let targetPassword = "12345678"
let targetAnnotation: String = "Acme Wireless"
let options: [String: NSObject] = [
kNEHotspotHelperOptionDisplayName: targetAnnotation as NSString
]
let queue = DispatchQueue(label: "com.example.test")
let isAvailable = NEHotspotHelper.register(options: options, queue: queue) { (command) in
switch command.commandType {
case .evaluate,
.filterScanList:
let originalNetworklist = command.networkList ?? []
let networkList = originalNetworklist.compactMap { network -> NEHotspotNetwork? in
print("networkName: \(network.ssid); strength: \(network.signalStrength)")
if network.ssid == targetSsid {
network.setConfidence(.high)
network.setPassword(targetPassword)
return network
}
return nil
}
let response = command.createResponse(.success)
response.setNetworkList(networkList)
response.deliver()
default:
break
}
}
assert(isAvailable)
关于swift - NEHotspotHelper.register 未收到回调 iOS11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46767138/
是否可以使用 NEHotspotHelper 测试原型(prototype)应用程序(开发部署)- 从应用程序连接到 WiFi 而无需请求 com.apple.developer.networking
我们试用了新的 NetworkExtension API。我们成功地在我们的应用程序中重新创建了所有步骤。但是,我们有一个问题,我们仍然没有在 Wifi 设置屏幕中看到 SSID 名称下方的自定义注释
我已经像他们说的那样提交了这个表格 https://developer.apple.com/contact/network-extension/ 然后我收到了苹果的邮件 Please note tha
我正在开发一款要求自动连接到 WiFi 网络的 iOS 应用。我们已向 Apple 请求 NEHotspotHelper 扩展,该扩展已获批准。 现在我正在尝试自动连接到周围的 WiFi 网络。但是对
我已经实现了 NEHotspotHelper,这样我就可以在后台为带有强制门户的网络执行身份验证。 我需要在“身份验证”状态下执行 Web 请求,以便我可以检索 Wispr 并访问 API。 但是,当
我已经为使用 Network Extension API 注册了我的应用程序,并根据评论 here 启用了后台模式.因此,当用户进入 wifi 设置时,我能够看到范围内的 wifis 列表,但我不知道
我正在使用 NEHotspotHelper 并尝试注册但没有收到回电。首先, I enabled Capability : Network Extensions 然后添加以下代码, let opti
当我尝试调用 registerWithOptions 它总是返回 false 时,您知道我的代码和设置中缺少什么吗? 我已经拥有 NetworkExtension 授权。 我已经创建了一个授权 并且已
我一直在将 NEHotspotHelper 整合到我管理强制网络的应用程序中,但我遇到了多个问题。在设置为高置信度的网络处于评估状态后,我没有收到身份验证命令 (kNEHotspotHelperCom
我现在正在实现一个将使用 NEHotspotHelper API 的项目。通过 Xamarin。 我知道这个 API 需要得到苹果的批准。所以我已经发送了我的请求并等待回复。 但我想先编写代码并在我的
我已经这样做了。 1。在苹果开发者页面添加IOS证书。 2。在 Apple Developer 页面中添加启用了网络扩展的标识符 App ID。 3。在 Apple Developer 页面中添加配置
我是一名优秀的程序员,十分优秀!