我是 iOS 新手,正在学习使用 Swift 编写代码。我的应用需要测量信号强度。我发现这段代码在 Objective-C/C 上工作,需要一些帮助才能在 Swift 上实现。这是我得到的。希望有人能帮我完成它。
目标 C
int getSignalStrength()
{
void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
int (*CTGetSignalStrength)();
CTGetSignalStrength = dlsym(libHandle, "CTGetSignalStrength");
if( CTGetSignalStrength == NULL) NSLog(@"Could not find CTGetSignalStrength");
int result = CTGetSignalStrength();
dlclose(libHandle);
return result;
}
迅速
func getSignalStrength()->Int{
var result : Int! = 0
let libHandle = dlopen ("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTD_LAZY)
** help **
var CTGetSignalStrength = dlsym(libHandle, "CTGetSignalStrength")
if (CTGetSignalStrength != nil){
result = CTGetSignalStrength()
}
dlclose(libHandle)
return result
}