16

I need to get my iOS device's phone number programatically.

Via google I found this code:

NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];
NSLog(@"Phone Number: %@", num);

But somewhere I read that if I use this code, Apple will reject my app.

Is there any way to get current device phone number without user entry?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Mahesh Babu
  • 3,395
  • 9
  • 48
  • 97

2 Answers2

24

No, the device's phone number is not available programmatically and still be approved by Apple, thankfully. I definitely don't want some free app I download out of curiosity to grab my phone number and start sending me spam SMS messages or have marketers calling me.

Matthew Frederick
  • 22,245
  • 10
  • 71
  • 97
  • interesting read: http://www.kuberan.me/2011/03/your-mobile-numbers-are-being-stolen-by-websites/ – Phill Pafford Mar 31 '11 at 13:41
  • @Phill That is interesting. Fortunately there's no "carrier billing" with the iPhone, so none of that data needs to be sent. You can see exactly what headers are being sent by either writing a simple "spit the headers back" web page (which is the first thing I did after reading this) or visiting a site that does the same thing. Here's one that shows you all of your headers, visit it from your iPhone to see exactly what is sent (visit from your laptop/desktop, too): http://www.ericgiguere.com/tools/http-header-viewer.html – Matthew Frederick Mar 31 '11 at 14:13
5

Your already have the answers:

Can any one pls help me is there any way to get current device number without user entry.

Yes, using the piece of code you have in your question.

And, YES, if you get phone number programmatically WITHOUT user input, your App will be rejected by Apple. This is plain and simple.

If you need the number, ask for it from the user. If they trust you, they will input the number.

Sarwar Erfan
  • 18,034
  • 5
  • 46
  • 57
  • if user enter wrong number how can we handle it.. – Mahesh Babu Jan 10 '11 at 06:51
  • 1
    Send a verification code via SMS (NOT from users phone, but from YOUR server using SMS gateway) to the number. Then ask the user to enter the number. – Sarwar Erfan Jan 10 '11 at 06:54
  • Why do you need the number? If you do not need to call(!) or sms to user's phone, please don't take it. If you do not need to call or sms the user, then rethink your model excluding the phone number. – Sarwar Erfan Jan 10 '11 at 06:55
  • i need to validate the user device number and phone number at server,if both are same i need to provide services.That's my requirement – Mahesh Babu Jan 10 '11 at 07:38
  • 1
    what if I ask user, "Can I detect your phone number and use it(will explain why I need phone number)?" and user permits to do so I run the code given by @MaheshBabu – chatur Jan 31 '12 at 12:30
  • Even if You ask user, "Can I detect your phone number and use it(will explain why I need phone number)?" Apple will still detect phone number getting method and reject your app. – Guntis Treulands May 08 '12 at 17:31