访问 CoreTelephony.framework

Get Access to CoreTelephony.framework

我正在使用 nst's iOS Runtime Headers 访问 CoreTelephony.framework。

这是他的示例代码:

NSBundle *b = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/FTServices.framework"];
BOOL success = [b load];

Class FTDeviceSupport = NSClassFromString(@"FTDeviceSupport");
id si = [FTDeviceSupport valueForKey:@"sharedInstance"];

NSLog(@"-- %@", [si valueForKey:@"deviceColor"]);

他的示例使用代码让我可以访问 FTServices.framework,但是当我应用相同的逻辑时,它失败了,因为 CoreTelephony 没有包含名为 sharedInstance() 的 class 方法。

我应该自己声明并实施还是有其他方法?

谢谢。

编辑:

我的尝试:

NSBundle *b = [NSBundle bundleWithPath:@"/System/Library/Frameworks/CoreTelephony.framework"];
BOOL success = [b load];

Class CTTelephonyNetworkInfo = NSClassFromString(@"CTTelephonyNetworkInfo");
id si = [CTTelephonyNetworkInfo valueForKey:@"sharedInstance"]; // fails here

NSLog(@"-- %@", [si valueForKey:@"cachedSignalStrength"]);

问题是CTTelephonyNetworkInfo其实没有属性sharedInstance。引用自 here, CTTelephonyNetworkInfo is a data structure designed to house the relevant info, and can be accessed (constructed) directly through the standard [[CTTelephonyNetworkInfo alloc] init] (referred from here).

所以对于你的情况:

NSBundle *b = [NSBundle bundleWithPath:@"/System/Library/Frameworks/CoreTelephony.framework"];
BOOL success = [b load];

Class CTTelephonyNetworkInfo = NSClassFromString(@"CTTelephonyNetworkInfo");
id si = [[CTTelephonyNetworkInfo alloc] init];

NSLog(@"-- %@", [si valueForKey:@"cachedSignalStrength"]);

尽管如此,请务必在实际 phone 上进行测试!模拟器没有存储此类信息。

编辑: 如果要在生成的 class 上调用方法,请使用 performSelector: or NSInvocation class.