1

I'm using nst's iOS Runtime Headers to get access to the CoreTelephony.framework.

Here is his sample code:

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"]);

His sample usage code gives me access to FTServices.framework but when I apply the same logic, it fails since CoreTelephony does not house a class method named sharedInstance().

Should I declare and implement that myself or is there another way?

Thanks.

EDIT:

My attempt:

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"]);
Can
  • 4,516
  • 6
  • 28
  • 50
  • Can you please post your own code attempt? Which class in CoreTelephony are you trying to access? – Flying_Banana Oct 26 '15 at 19:17
  • @Flying_Banana Please see the edit. – Can Oct 26 '15 at 19:29
  • Why are you trying to access it like that? CoreTelephony is a public framework. – dan Oct 26 '15 at 19:52
  • @dan I'm aware of it but I need access to things private in that public framework for research purposes. Am I on the wrong path? – Can Oct 26 '15 at 19:56
  • Yes, you can just create a `CTTelephonyNetworkInfo` object normally and then access the private property you want using `valueForKey:` like the last line in your snippet. – dan Oct 26 '15 at 20:01
  • @dan Yeah that worked. Thanks. But how can I access instance methods as well. They're not defined in the public headers. – Can Oct 26 '15 at 20:17

1 Answers1

3

The problem is that CTTelephonyNetworkInfo actually has no property sharedInstance. Referred from 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).

So for your case:

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"]);

Make sure you test on an actual phone though! Simulators have no such information stored.

Edits: If you want to call methods on a generated class, use performSelector: or NSInvocation class.

Community
  • 1
  • 1
Flying_Banana
  • 2,864
  • 2
  • 22
  • 38
  • The sample usage works for me as well. It's just that I can't modify it to work with CoreTelephony. – Can Oct 26 '15 at 19:14
  • Edited. Sorry about the initial answer, thought it was your own attempt! :) – Flying_Banana Oct 26 '15 at 19:35
  • Could you also share a snippet as well please? – Can Oct 26 '15 at 19:51
  • Tried your snippet on an actual device but returned null. Also how can I call methods? – Can Oct 26 '15 at 20:22
  • Apparently that `CTTelephonyNetworkInfo` only gives you access to the carrier's information, as referred from [Apple's description](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/CTTelephonyNetworkInfo/index.html#//apple_ref/occ/cl/CTTelephonyNetworkInfo). I've updated the answer for calling methods. – Flying_Banana Oct 26 '15 at 20:37
  • Maybe it's that CoreTelephony requires entitlement in order to work. Anyways, much appreciated! – Can Oct 27 '15 at 14:56