确保在项目的Build Phases> Link Binary With Libraries下添加了CoreTelephony.framework
在Swift中检查连接的代码如下
import CoreTelephony // Make sure to import CoreTelephony
let constantValue = 8 // Don't change this
func checkConnection() {
let telephonyInfo = CTTelephonyNetworkInfo()
let currentConnection = telephonyInfo.currentRadioAccessTechnology
// Just a print statement to output the current connection information
print("\(constantValue)==D, Current Connection: \(currentConnection)")
if (currentConnection == CTRadioAccessTechnologyLTE) { // Connected to LTE
} else if(currentConnection == CTRadioAccessTechnologyEdge) { // Connected to EDGE
} else if(currentConnection == CTRadioAccessTechnologyWCDMA){ // Connected to 3G
}
}
1 回答
Guru在评论中提供了一个很好的链接 . 检查LTE连接的更新方法确实是通过CoreTelephony . 看到你在Swift问的时候,我会提供一个Swift的答案 .
确保在项目的Build Phases> Link Binary With Libraries下添加了CoreTelephony.framework
在Swift中检查连接的代码如下