Cordova / Phonegap获取设备的电话号码(Android&iOS)

问题描述:

是否可以使用Phonegap / Cordova开发混合移动应用程序,并访问Android和iOS的设备电话号码?

Is it possible to develop a hybrid mobile app using Phonegap / Cordova and access the device phone number for both Android and iOS?

iOS:
您可以使用CoreTelephony框架检索电话号码,您需要添加以下授权: com.apple.coretelephony.Identity.get
然而,一旦您的应用程序上传到AppStore,苹果可能会拒绝。
但是,如果您计划使用企业分发计划分发,您应该没有问题,请参阅Igor Fedorchuk和Dylan的回答此处,以及另一篇详细阐述的此处

iOS: You can retrieve the phone number using the CoreTelephony framework, you will need to add the following Entitlement: com.apple.coretelephony.Identity.get. However apple might reject your app once you upload it to the AppStore. However, if you plan to distribute using the "Enterprise Distribution" plan, you should have no problem at all, see answers by Igor Fedorchuk and Dylan here, and another elaborated answer here.

Android:
是的,您可以使用此插件,或者编写一个cordova插件,桥接以下代码:

Android: Yes, you could use this plugin, or write a cordova plugin that bridges the following code:

TelephonyManager tm = (TelephonyManager)appContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tm.getLine1Number();

所需的权限是 android.permission.READ_PHONE_STATE