By Vadim

2008-10-10 22:03:53 8 Comments

Is there any way to get own phone number by standard APIs from iPhone SDK?


@thedazed 2018-08-30 08:17:24

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 :

@davidgyoung 2018-07-13 16:34:59

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.

@Nick 2018-11-29 08:10:48

The demo video is not found can you update?

@davidgyoung 2018-11-29 12:14:58

Sorry. Video was accidentally private. It is public now.

@Motti Shneor 2019-02-06 09:33:54

This 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?

@davidgyoung 2019-02-06 13:56:42

@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.

@Andrew Grant 2008-10-10 22:58: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.

@JosephH 2013-06-10 10:16:23

See Nik Burn's answer: - there is (sort of) a way to do this!

@Crashalot 2016-03-22 06:00:09

What'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.

@Robert Sanders 2008-10-22 03:09:03

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)


and so on.

Not sure what, if anything, the others do.

@JeffH 2009-09-30 15:46:36

There's been some recent press about the security concerns behind this ability:

@Bryan 2009-11-10 02:59:44

Any updates on the press and Apple's resolution?

@Mugunth 2009-11-20 23:51:09

Apple just rejected my app for using this.

@David Kanarek 2010-01-18 23:32:16

Don'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.

@averydev 2011-10-27 20:32:22

A solution that gets apps rejected is not a solution.

@Dishant Rajput 2016-11-23 11:41:50

You can not get your own phone number due to some security reason but you can fetch your number. Save it to your contact list and then you can fetch your number programmatically.

@0x8BADF00D 2014-09-18 23:02:40

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();
    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?

@David Gölzhäuser 2013-03-28 09:46:22

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/";
    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.

@respectTheCode 2014-04-24 19:18:57

This doesn't work on iOS 7.

@Sankalap Yaduraj Singh 2017-01-25 13:31:49

This doesn't work on iOS 10 and above.

@Igor 2012-08-30 14:28:04

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.

@Mehul Thakkar 2013-12-11 12:07:07

After reading other answers in this forum, i was thinking it is not possible but you have done perfect job

@user501836 2014-02-25 03:14:41

this not work on iOS7

@creker 2014-04-30 06:43:36

On iOS 7 it's protected by the entitlement…

@c1pherB1t 2016-09-12 20:00:30

phone is nil when I try this

@Andres Garcia 2010-05-25 00:03:18

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

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!

@Raptor 2012-01-06 06:19:58

uniqueIdentifier is also deprecated in iOS5. Use MAC address instead.

@jab 2013-11-20 21:14:27

MAC address is deprecated in iOS 7. Use [UIDevice identifierForVendor] instead.

@Dylan 2009-11-06 04:16:35

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.

@rgbrgb 2013-02-07 02:34:06

How does Snapchat do it?

@Abhishek Bedi 2013-05-20 07:59:03

@Dylan : When was your app rejected.Perhaps the guidelines are revised? Please provide useful links to documentation. However, I appreciate your answer.

@Ganesh AB - Android 2015-08-18 05:45:15

Can I get apple.developer documentation link where this mentioned ?

@Saumil Shah 2015-11-04 12:36:23

Can any one provide me a link of apple.developer documentation link? where this mentioned ?

@Sudheesh 2016-04-13 09:21:43

@Dylan Any documentation Link.

@Dylan 2016-05-10 03:37:22

I 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.

@William Entriken 2017-10-09 14:34:20

@rgbrgb I don't use Snapchat, can you please explain their experience that is so mystifying?

@madprogramer 2017-10-16 11:41:52

@rgbrgb Same here, could really use that knowledge

@Sam 2018-02-22 10:42:05

@rgbrgb Snap asks the user for their number upon signup.

@davidgyoung 2018-07-13 16:38:44

If 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

@aqavi_paracha 2019-01-02 09:54:55

It's now possible in Xcode like this

@Ash 2019-03-03 03:16:08

How the f&@k does WhatsApp do it then? You don’t have to physically enter a number, it just knows.

@Pulkit Kumar Singh 2019-05-21 18:32:36

@Ash i too got that message .... there might be some change in documentation..will have to see

Related Questions

Sponsored Content

22 Answered Questions

[SOLVED] How to link to apps on the app store

14 Answered Questions

[SOLVED] How to mark-up phone numbers?

32 Answered Questions

[SOLVED] Can I embed a custom font in an iPhone application?

  • 2008-12-11 20:21:11
  • Airsource Ltd
  • 234689 View
  • 768 Score
  • 32 Answer
  • Tags:   ios cocoa-touch fonts

40 Answered Questions

[SOLVED] How can I develop for iPhone using a Windows development machine?

  • 2008-08-22 13:35:01
  • ryan
  • 1093812 View
  • 1144 Score
  • 40 Answer
  • Tags:   ios iphone windows

10 Answered Questions

[SOLVED] How do you beta test an iphone app?

  • 2008-09-02 17:52:24
  • Michael Pryor
  • 195604 View
  • 453 Score
  • 10 Answer
  • Tags:   ios beta-testing

15 Answered Questions

[SOLVED] How can my iphone app detect its own version number?

  • 2009-01-19 18:32:22
  • cmos
  • 107283 View
  • 249 Score
  • 15 Answer
  • Tags:   iphone ios version

15 Answered Questions

14 Answered Questions

[SOLVED] Xcode process launch failed: Security

39 Answered Questions

[SOLVED] A comprehensive regex for phone number validation

24 Answered Questions

[SOLVED] How to disable phone number linking in Mobile Safari?

Sponsored Content