Is there any way to get own phone number by standard APIs from iPhone SDK?
-
may be useful for others searching for a solution that does not use private api's [how-does-squares-cardcase-app-do-this - use device name to capture users name](http://stackoverflow.com/questions/8000927/how-does-squares-cardcase-app-do-this/8058188#8058188) just amend to capture phone number or other details as appropriate – Nik Burns Dec 07 '11 at 12:14
-
davidgyoung has provided a working solution. It is buried (needs some upvotes). – P i Sep 24 '18 at 19:47
9 Answers
At the risk of getting negative marks, I want to suggest that the highest ranking solution (currently the first response) violates the latest SDK Agreement as of Nov 5, 2009. Our application was just rejected for using it. Here's the response from Apple:
"For security reasons, iPhone OS restricts an application (including its preferences and data) to a unique location in the file system. This restriction is part of the security feature known as the application's "sandbox." The sandbox is a set of fine-grained controls limiting an application's access to files, preferences, network resources, hardware, and so on."
The device's phone number is not available within your application's container. You will need to revise your application to read only within your directory container and resubmit your binary to iTunes Connect in order for your application to be reconsidered for the App Store.
This was a real disappointment since we wanted to spare the user having to enter their own phone number.

- 3,658
- 1
- 21
- 12
-
1@Dylan : When was your app rejected.Perhaps the guidelines are revised? Please provide useful links to documentation. However, I appreciate your answer. – Abhishek Bedi May 20 '13 at 07:59
-
1
-
Can any one provide me a link of apple.developer documentation link? where this mentioned ? – Saumil Shah Nov 04 '15 at 12:36
-
-
3I have never found any documentation on this, but would love to see it. It's one of those areas where Apple has remained opaque for me. I have not tried to submit an application since this. – Dylan May 10 '16 at 03:37
-
1@rgbrgb I don't use Snapchat, can you please explain their experience that is so mystifying? – William Entriken Oct 09 '17 at 14:34
-
-
1
-
1If you are interested in capturing the phone number by sending an SMS message (similar to Snapchat but simpler IMO), see my answer below and described in detail in the blog post [here](http://www.davidgyoungtech.com/2018/07/13/capturing-mobile-phone-numbers) – davidgyoung Jul 13 '18 at 16:38
-
1How the f&@k does WhatsApp do it then? You don’t have to physically enter a number, it just knows. – Ash Mar 03 '19 at 03:16
-
@Ash i too got that message .... there might be some change in documentation..will have to see – Pulkit Kumar Singh May 21 '19 at 18:32
No, there's no legal and reliable way to do this.
If you find a way, it will be disabled in the future, as it has happened with every method before.

- 6,006
- 7
- 38
- 48

- 58,260
- 22
- 130
- 143
-
2See Nik Burn's answer: http://stackoverflow.com/a/8415162/292166 - there is (sort of) a way to do this! – JosephH Jun 10 '13 at 10:16
-
4What's the best reason you have seen for Apple disallowing permission-based access to the user's phone number? Apple already allows permission-based access to contacts, photos, location, and the user's camera and microphone. Why not the phone number? There must be a good reason, but it's not immediately clear. It's unfortunate because prohibiting access causes devs to spend a lot of time and money on other ways to verify a user's phone number. – Crashalot Mar 22 '16 at 06:00
Update: capability appears to have been removed by Apple on or around iOS 4
Just to expand on an earlier answer, something like this does it for me:
NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];
Note: This retrieves the "Phone number" that was entered during the iPhone's iTunes activation and can be null or an incorrect value. It's NOT read from the SIM card.
At least that does in 2.1. There are a couple of other interesting keys in NSUserDefaults that may also not last. (This is in my app which uses a UIWebView)
WebKitJavaScriptCanOpenWindowsAutomatically
NSInterfaceStyle
TVOutStatus
WebKitDeveloperExtrasEnabledPreferenceKey
and so on.
Not sure what, if anything, the others do.

- 6,006
- 7
- 38
- 48

- 720
- 2
- 11
- 16
-
1There's been some recent press about the security concerns behind this ability: http://www.theregister.co.uk/2009/09/30/iphone_security/ – JeffH Sep 30 '09 at 15:46
-
11Don't do it. Ask the user for the number via keypad or contact chooser. You should make any information gathering as explicit as possible to the user. It may not be the most convenient, but it's very easy to save the number, so you only have to ask for it once. – David Kanarek Jan 18 '10 at 23:32
-
4
Using Private API you can get user phone number on the following way:
extern NSString* CTSettingCopyMyPhoneNumber();
+(NSString *) phoneNumber {
NSString *phone = CTSettingCopyMyPhoneNumber();
return phone;
}
Also include CoreTelephony.framework to your project.

- 4,235
- 3
- 34
- 32
-
After reading other answers in this forum, i was thinking it is not possible but you have done perfect job – Mehul Thakkar Dec 11 '13 at 12:07
-
1On iOS 7 it's protected by the entitlement http://stackoverflow.com/questions/19504478/ios-7-how-to-get-own-number-via-private-api/20830611#20830611 – creker Apr 30 '14 at 06:43
-
You cannot use iOS APIs alone to capture the phone number (even in a private app with private APIs), as all known methods of doing this have been patched and blocked as of iOS 11. Even if a new exploit is found, Apple has made clear that they will reject any apps from the app store for using private APIs to do this. See @Dylan's answer for details.
However, there is a legal way to capture the phone number without any user data entry. This is similar to what Snapchat does, but easier, as it does not require the user to type in their own phone number.
The idea is to have the app programmatically send a SMS message to a server with the app’s unique installation code. The app can then query the same server to see if it has recently received a SMS message from a device with this unique app installation code. If it has, it can read the phone number that sent it. Here’s a demo video showing the process. As you can see, it works like a charm!
This is not super easy to set up, but it be configured in a few hours at no charge on a free AWS tier with the sample code provided in the tutorial here.

- 63,876
- 14
- 121
- 204
-
-
1This is a great way, but could you please enrich your answer to at least cover the basic implementation details? How do you send an SMS from an iOS device without knowing your phone number? how do you set up an SMS-receiving server that has access to the sender's phone-number? What tools are involved? compatibility? – Motti Shneor Feb 06 '19 at 09:33
-
@MottiShneor, did you see the tutorial link in the answer? This has a full tutorial on setting up this solution as well as a working sample app code in a Github repo. – davidgyoung Feb 06 '19 at 13:56
-
Has anyone implemented this approach and deployed to App Store? Curious whether App Store Review (or newer Play Store Review) would have a problem with this. – Alexander Wallace Matchneer Oct 07 '22 at 22:17
-
1I used this for an enterprise app so I did not send it for review. But since the user is in control of sending the SMS message via the dialog they see, I doubt either Apple or Google would have a problem with it provided that you disclose that you are sending the SMS to verify their phone number. – davidgyoung Oct 08 '22 at 23:10
-
This is genius, might try this out in a app store app in 2023 and see if it flies – Jonovono Mar 16 '23 at 23:34
As you probably all ready know if you use the following line of code, your app will be rejected by Apple
NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];
here is a reference
http://ayeapi.blogspot.com/2009/12/sbformatphonenumber-is-lie.html
you can use the following information instead
NSString *phoneName = [[UIDevice currentDevice] name];
NSString *phoneUniqueIdentifier = [[UIDevice currentDevice] uniqueIdentifier];
and so on
@property(nonatomic,readonly,retain) NSString *name; // e.g. "My iPhone"
@property(nonatomic,readonly,retain) NSString *model; // e.g. @"iPhone", @"iPod Touch"
@property(nonatomic,readonly,retain) NSString *localizedModel; // localized version of model
@property(nonatomic,readonly,retain) NSString *systemName; // e.g. @"iPhone OS"
@property(nonatomic,readonly,retain) NSString *systemVersion; // e.g. @"2.0"
@property(nonatomic,readonly) UIDeviceOrientation orientation; // return current device orientation
@property(nonatomic,readonly,retain) NSString *uniqueIdentifier; // a string unique to each device based on various hardware info.
Hope this helps!

- 70,108
- 23
- 141
- 204

- 231
- 2
- 2
-
9
-
15MAC address is deprecated in iOS 7. Use `[UIDevice identifierForVendor]` instead. – jab Nov 20 '13 at 21:14
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]);
I don't know if Apple allow this but it works on iPhones.

- 3,525
- 8
- 50
- 98
-
Apple voids the warranty on jailbroken phones and an app would need to have ubiquitous capability for all users. – Cosmtar Jan 15 '20 at 13:34
No official API to do it. Using private API you can use following method:
-(NSString*) getMyNumber {
NSLog(@"Open CoreTelephony");
void *lib = dlopen("/Symbols/System/Library/Framework/CoreTelephony.framework/CoreTelephony",RTLD_LAZY);
NSLog(@"Get CTSettingCopyMyPhoneNumber from CoreTelephony");
NSString* (*pCTSettingCopyMyPhoneNumber)() = dlsym(lib, "CTSettingCopyMyPhoneNumber");
NSLog(@"Get CTSettingCopyMyPhoneNumber from CoreTelephony");
if (pCTSettingCopyMyPhoneNumber == nil) {
NSLog(@"pCTSettingCopyMyPhoneNumber is nil");
return nil;
}
NSString* ownPhoneNumber = pCTSettingCopyMyPhoneNumber();
dlclose(lib);
return ownPhoneNumber;
}
It works on iOS 6 without JB and special signing.
As mentioned creker on iOS 7 with JB you need to use entitlements to make it working.
How to do it with entitlements you can find here: iOS 7: How to get own number via private API?

- 1
- 1

- 7,138
- 2
- 41
- 34
AppStore will reject it, as it's reaching outside of application container.
Apps should be self-contained in their bundles, and may not read or write data outside the designated container area
Section 2.5.2 : https://developer.apple.com/app-store/review/guidelines/#software-requirements