如何获取iOS中的WLAN ISP名称?

How can I obtain the WLAN ISP name in iOS?

各位溢出者,

我正在使用最新的 SDK (11.2)[= 开发 iOS 应用程序 32=]4.

我正在寻找获取 WLAN ISP 名称的方法。

(比如我家的ISP叫NET1 Ltd.

提前致谢!

Core WLAN框架提供查询AirPort接口和选择网络的API。

Core Telephony framework provides information about a user’s cellular service provider. You can use CTCarrier class 获取有关用户的家庭蜂窝服务提供商的信息。

如果您的 iOS 设备有 SIM 卡,

CTCarrier 只会 return 运营商信息。获得它的更好方法是通过像 ipinfo.io 这样的网络服务。这是 Playground 中的示例:

import PlaygroundSupport
import Foundation

PlaygroundPage.current.needsIndefiniteExecution = true

let url = URL(string: "https://ipinfo.io/org")!
URLSession.shared.dataTask(with: url) { data, response, error in
    guard error == nil else { print(error!); return }
    guard let data = data else { print("Empty data"); return }

    if let ispName = String(data: data, encoding: .utf8) {
        print(ispName)
    } else {
        print("Can't obtain ISP name")
    }
}.resume()