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?
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With