Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the device's phone number programmatically [duplicate]

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?

like image 226
Mahesh Babu Avatar asked Jan 10 '11 06:01

Mahesh Babu


People also ask

How can I get mobile number programmatically?

Navigate to the app > res > layout > activity_main. xml and add the below code to that file. Create a TextView to display the mobile number.

How do I get the IOS phone number programmatically?

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. and so on.

How can I get mobile number details in Android?

On Android the most common path to finding your number is: Settings > About phone/device > Status/phone identity > Network. This slightly differs on Apple devices, where you can follow the path of Settings > Phone > My Number.

How do I find my SIM card number on Android?

You can also use your phone's settings to find out your phone number. However, the most popular and the easiest method to find out the mobile number from SIM is the dial the USSD code given by the respective network provider for this purpose. Here are the USSD codes of different networks to find out the mobile number.


2 Answers

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.

like image 181
Matthew Frederick Avatar answered Oct 06 '22 03:10

Matthew Frederick


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.

like image 33
Sarwar Erfan Avatar answered Oct 06 '22 03:10

Sarwar Erfan