以前网上流行两种方式获取iPhone本机号码:api
1.读取用户设置的号码app
NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];
2.私有api,须要CoreTelephony.framework的支持less
extern NSString* CTSettingCopyMyPhoneNumber(); -(NSString *) phoneNumber { NSString *phone = CTSettingCopyMyPhoneNumber(); return phone; }
不过1的方式早已经失效,而2的方式也一直取不到值。后来在谷歌上百度了好多圈,终于找到了方法:spa
3.读取plist文件code
NSString *commcenter = @"/private/var/wireless/Library/Preferences/com.apple.commcenter.plist"; NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:commcenter]; NSString *PhoneNumber = [dict valueForKey:@"PhoneNumber"]; NSLog([NSString stringWithFormat:@"Phone number: %@",PhoneNumber],nil);
固然了,看代码也知道,须要越狱机才行。苹果PP助手经过数据线链接iPhone以后能够读取到本机号码,不须要越狱,我还不知道其方法。orm
但愿知道的能给我说下,(*^__^*) 嘻嘻……。blog