3

I would like to programatically get the device phone number (on iOS5 and iOS6).
Are there any unofficial ways for doing so?

Are there any private Core Telephony APIs or IOKit APIs that can be used for example?

And yes I do know my app won't be accepted in the AppStore

Victor Ronin
  • 22,758
  • 18
  • 92
  • 184
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378

2 Answers2

6

Private API

There is a private API to get phone number. Private API can't be submitted to AppStore, but it can be executed on jailed device.

NSString* CTSettingCopyMyPhoneNumber();

It returns phone number. And it's located in CoreTelephony

MDM

And actually, there is even a legal way of getting phone number. However, it's complicated. There is MDM protocol for iOS. One of the commands retrieves information about a device and this info includes phone number (and a lot of other device info).

Other notes

Also, you may be interested to read through these several questions:

Programmatically get own phone number in iOS

How can I get the phone number of my iPhone device?

Community
  • 1
  • 1
Victor Ronin
  • 22,758
  • 18
  • 92
  • 184
  • Thanks however I read another posting in here saying CTSettingCopyMyPhoneNumber used to be present but has since been removed, can you confirm this? – Gruntcakes Apr 01 '13 at 22:42
  • Official documentation is available only if you signed up with Apple for Enterprise Developer program. Unofficial documentation is here: http://media.blackhat.com/bh-us-11/Schuetz/BH_US_11_Schuetz_InsideAppleMDM_WP.pdf – Victor Ronin Apr 01 '13 at 22:45
  • Regarding being remove. I just run Core Telephony through a dissassembler. It's still present. I will try to use it and let you know whether it's still usable. – Victor Ronin Apr 01 '13 at 22:46
  • Actually I do have an enterprise account, but I didn't know there was an additional section of documentation available only to enterprise account holders. Does this mean the MDM mechanism is only legal for enterprise apps? – Gruntcakes Apr 01 '13 at 22:47
  • 1
    I just checked. CTSettingsCopymyPhoneNumber works fine. MDM documentation is under iOS Provisioning Portal->Certificates->Other->Moble Device Management protocol. MDM protocol is the protocol between iOS device and the server. iOS device can enroll into MDM server and after that MDM server can send commands to iOS device (including a request about device info). – Victor Ronin Apr 01 '13 at 22:53
  • If you are interested in MDM protocol, I would recommend to read additional these pages: http://developer.apple.com/library/ios/#featuredarticles/iPhoneConfigurationProfileRef/Introduction/Introduction.html http://manuals.info.apple.com/en_US/Enterprise_Deployment_guide.pdf http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/iPhoneOTAConfiguration/OTASecurity/OTASecurity.html – Victor Ronin Apr 01 '13 at 22:54
  • Thanks, I'll check them out. – Gruntcakes Apr 01 '13 at 23:01
  • @VictorRonin I have tried the CTSettingCopyMyPhoneNumber. It retrieves the phone number from the setting which can be changed, right? just wanna make sure – pt2121 Apr 23 '13 at 15:41
  • @EntryLevelDev: I am not sure. I play with a lot of private API's, but quite often I don't investigate each of them too deep. So, the best idea would be just to try it. BTW. I saw that you became very active in private API's area. I would appreciate, if you can send me an email (my email address is in profile). I try to keep in touch with people who are interested in this (rare) area. – Victor Ronin Apr 23 '13 at 17:20
  • @VictorRonin I just tested CTSettingCopyMyPhoneNumber. The problem is if a user change a phone number on the setting, we'll get that number. I will send you the email if I have a chance. I've learned a lot from your answers actually. good to keep in touch. – pt2121 Apr 23 '13 at 18:52
  • @VictorRonin I am so curious how Apple populates the phone number from sim card. there must be a private api for that. – pt2121 Apr 24 '13 at 14:18
  • @EntryLevelDev: I saw SIMToolkit in CoreTelephony (http://stackoverflow.com/questions/16074190/is-there-a-private-api-available-to-access-the-sim-toolkit/16086489#16086489). There could be something in there. – Victor Ronin Apr 24 '13 at 14:44
3

You could start by searching in the private headers.

nevan king
  • 112,709
  • 45
  • 203
  • 241