Programmatically get own phone number in iOS

2018-12-31 02:15发布

Is there any way to get own phone number by standard APIs from iPhone SDK?

11条回答
不再属于我。
2楼-- · 2018-12-31 02:28

As you probably all ready know if you use the following line of code, your app will be rejected by Apple

NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];

here is a reference

http://ayeapi.blogspot.com/2009/12/sbformatphonenumber-is-lie.html

you can use the following information instead

NSString *phoneName = [[UIDevice currentDevice] name];

NSString *phoneUniqueIdentifier = [[UIDevice currentDevice] uniqueIdentifier];

and so on

@property(nonatomic,readonly,retain) NSString    *name;              // e.g. "My iPhone"
@property(nonatomic,readonly,retain) NSString    *model;             // e.g. @"iPhone", @"iPod Touch"
@property(nonatomic,readonly,retain) NSString    *localizedModel;    // localized version of model
@property(nonatomic,readonly,retain) NSString    *systemName;        // e.g. @"iPhone OS"
@property(nonatomic,readonly,retain) NSString    *systemVersion;     // e.g. @"2.0"
@property(nonatomic,readonly) UIDeviceOrientation orientation;       // return current device orientation
@property(nonatomic,readonly,retain) NSString    *uniqueIdentifier;  // a string unique to each device based on various hardware info.

Hope this helps!

查看更多
心情的温度
3楼-- · 2018-12-31 02:30

No, there's no legal and reliable way to do this.

If you find a way, it will be disabled in the future, as it has happened with every method before.

查看更多
若你有天会懂
4楼-- · 2018-12-31 02:38

Update: capability appears to have been removed by Apple on or around iOS 4


Just to expand on an earlier answer, something like this does it for me:

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.

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)

WebKitJavaScriptCanOpenWindowsAutomatically
NSInterfaceStyle
TVOutStatus
WebKitDeveloperExtrasEnabledPreferenceKey

and so on.

Not sure what, if anything, the others do.

查看更多
骚的不知所云
5楼-- · 2018-12-31 02:42

You can ask the user m.phone and verficate it using sms. Legally, no method for knows it.

查看更多
裙下三千臣
6楼-- · 2018-12-31 02:42

You can not get your own phone number due to some security reason but you can fetch your number. Save it to your contact list and then you can fetch your number programmatically.

查看更多
低头抚发
7楼-- · 2018-12-31 02:44

Using Private API you can get user phone number on the following way:

extern NSString* CTSettingCopyMyPhoneNumber();


+(NSString *) phoneNumber {
NSString *phone = CTSettingCopyMyPhoneNumber();

return phone;
}

Also include CoreTelephony.framework to your project.

查看更多
登录 后发表回答