无法从 iPhone 获取电话号码
目前我正在使用以下代码来获取本地设备电话号码:
NSString *num = [[NSUserDefaults standardUserDefaults]
stringForKey:@”SBFormattedPhoneNumber”];
NSLog(@”Phone Number: %@”, num);
但它无法获取该号码,它显示为空。谁能指导我如何解决这个问题!!
提前致谢
Currently I'm using the following code to get the local device phone number :
NSString *num = [[NSUserDefaults standardUserDefaults]
stringForKey:@”SBFormattedPhoneNumber”];
NSLog(@”Phone Number: %@”, num);
but it can't able to get the number, it shows null. Can any one guide me how to solve this problem!!
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不支持获取设备电话号码的方法。目前有效的任何方法(例如其他答案中提到的“SBFormattedPhoneNumber”)都可能会导致您的应用程序被拒绝,并且可能会在任何时候停止工作,恕不另行通知。
如果您需要电话号码,只需要求用户输入即可。
There is no supported way to get the device's phone number. Any method (such as "SBFormattedPhoneNumber" mentioned in the other answers) that happens to work for now is liable to get your app rejected and is liable to stop working at any point without notice.
If you need the phone number, just ask the user to enter it.
使用下面的代码
来存储电话号码字符串
以取回电话字符串。
阅读博客教程。
http://ayeapi.blogspot.com/2009/12/sbformatphonenumber-is -lie.html
Use below code
To Store a phone number string
To get the phone string back.
Read the blog tutorial.
http://ayeapi.blogspot.com/2009/12/sbformatphonenumber-is-lie.html
这是解决方案!检查此链接或阅读从同一链接回答下面!
来自链接的回答:
只是要扩展之前的答案,类似这样的事情对我来说是这样的:
注意:这会检索在 iPhone 的 iTunes 激活期间输入的“电话号码”,并且可以为 null 或不正确的值。 不从 SIM 卡读取。
至少在 2.1 中是这样。 NSUserDefaults 中还有一些其他有趣的键,但它们可能也不会持久。 (这是在我使用 UIWebView 的应用程序中)
等等。
不确定其他人做了什么(如果有的话)。
Here is the solution !!! Check this link or read answer below from same link !!!
Answer from LINK:
Just to expand on an earlier answer, something like this does it for me:
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.
将数据保存到 NSUserDefaults。
它可能会帮助你..
Saving Data to NSUserDefaults.
It may help you..