Getting the local iPhone number through SDK

假装没事ソ 提交于 2019-11-28 09:34:30

There's no reliable way. You'll find code online that tells you to look up SBFormattedPhoneNumber, and sometimes that works, but not consistently. Mostly it's people who brought their phone number over from another cell carrier. In those cases, you get a phone number, but not one for the current phone, and not one that's guaranteed to be valid for anything at all (it may not even be unique).

I have no basis for saying whether this is a few people or a lot, but it's an undocumented key that's inherently unreliable.

This method refers to the number stored in iTunes at time of activation... so, don't use it. From 4.x you can take advantage from CoreTelephony framework to get many information about the network, but still no number...

Mak
CFShow([[NSUserDefaults standardUserDefaults] objectForKey:@"SBFormattedPhoneNumber"]); 

NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Preferences/.GlobalPreferences.plist"];  
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];  
CFShow(dict); 

Take a look at this blog post here.

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

Adrian

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!