6

Yes I know full well its not possible to get the phone number using public APIs.

I want to know what the latest situation is regarding how to get the phone number using private APIs for an enterprise app with iOS11. All the past questions I could find are years old, couldn't find anything recent.

I tried this:

extern NSString* CTSettingCopyMyPhoneNumber();
+(NSString *) phoneNumber
{
    NSString *phone = CTSettingCopyMyPhoneNumber();
    return phone;
}

But am not able to run this however as I wasn't able to add the com.apple.coretelephony.Identity.get entitlement without getting a signing error saying the executable was signed with invalid entitlements.

Is it still possible with iOS 11 to get the phone number programmatically using non-public APIs for an enterprise app on a non jailbroken device?

Ami Patel
  • 71
  • 6
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • Apple doesn't make the phone number associated with a device available to developers. https://forums.developer.apple.com/thread/9171 – Muhammad Zeshan Arif Feb 21 '18 at 20:05
  • 1
    Use the SMS API to send the UIDevice code to a number you own. Most SMS services are free to receive messages. Then make a web service request to get the telephone number by UIDevice code. Only way to do it. – Greg Feb 22 '18 at 11:16
  • Interestingly `CTSettingCopyMyPhoneNumber()` and `[[AKDevice currentDevice] phoneNumber]` rely internally on a `XPC` inter process call. This is the actual fetch mechanism heavily guarded for the valid entitlement. – Kamil.S Feb 22 '18 at 12:27
  • @Zeshan Arif. There is a difference between publicly available and privately available. The MDN is available, the question is how to get it in iOS 11. There have been a variety of ways of obtaining it in previous versions of iOS 11. – Gruntcakes Feb 22 '18 at 16:32
  • @Gruntcakes To get you phone number you can read a plist file. It will not work on non-jailbroken iDevices: NSString *commcenter = @"/private/var/wireless/Library/Preferences/com.apple.commcenter.plist"; NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:commcenter]; NSString *PhoneNumber = [dict valueForKey:@"PhoneNumber"]; NSLog([NSString stringWithFormat:@"Phone number: %@",PhoneNumber]); – Muhammad Zeshan Arif Feb 22 '18 at 16:47
  • Not sure how good of a solution this would be, but how about getting the user's iCloud name and looking for the same name in the contacts for finding the phone number. This will require the user to allow user discoverability and access to contacts. But you can make it mandatory for them to use the app since its for the enterprise. – Sam Feb 23 '18 at 07:58

0 Answers0