How to programmatically get phone number with iOS11 for Enterprise app
Asked Answered
A

0

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?

Apprentice answered 13/2, 2018 at 21:54 Comment(6)
Apple doesn't make the phone number associated with a device available to developers. forums.developer.apple.com/thread/9171Co
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.Bimetallism
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.Sequacious
@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.Apprentice
@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]);Co
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.Concurrence

© 2022 - 2024 — McMap. All rights reserved.