ios 以编程方式获取设备的电话号码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4644145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the device's phone number programmatically
提问by Mahesh Babu
I need to get my iOS device's phone number programatically.
我需要以编程方式获取我的 iOS 设备的电话号码。
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.
但是我在某处读到,如果我使用此代码,Apple 将拒绝我的应用程序。
Is there any way to get current device phone number without user entry?
有没有办法在没有用户输入的情况下获取当前设备电话号码?
回答by Matthew Frederick
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.
不,该设备的电话号码无法以编程方式提供,并且仍然得到 Apple 的批准,谢天谢地。我绝对不想要一些我出于好奇而下载的免费应用程序来获取我的电话号码并开始向我发送垃圾短信或让营销人员给我打电话。
回答by Sarwar Erfan
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.
而且,是的,如果您在没有用户输入的情况下以编程方式获取电话号码,您的应用程序将被 Apple 拒绝。这是简单明了的。
If you need the number, ask for it from the user. If they trust you, they will input the number.
如果您需要该号码,请向用户索取。如果他们信任你,他们会输入号码。