I'm very new to ionic and cordova. I want to get user's phone number somehow, is it possible? I'm trying to create number registration for my app. When user opens an app the very first time he is asked to enter a code that he gets via text message. It's similar to viber. The first view contains a button 'Send me a code', and the next view has a form 'Enter code:' and a button 'Log me in'.
Ionic Native is a curated set of wrappers for Cordova plugins that make adding any native functionality you need to your Ionic mobile app easy. Ionic Native wraps plugin callbacks in a Promise or Observable, providing a common interface for all plugins and making it easy to use plugins with Angular change detection.
I think this plugin will full fill your needs (https://github.com/vliesaputra/DeviceInformationPlugin). It will give the following data
1.Your unique Device ID
2.Phone Number (if it is stored in your SIM card)
3.Country ISO of your phone network provider
4.Name of your network provider
5.Your SIM Card Serial number
6.Country ISO of your SIM card 7.Name of your SIM card mobile operator
8.E-mail/Phone number used by apps listed in your Settings > Accounts & Sync list
Here is sample code
var deviceInfo = cordova.require("cordova/plugin/DeviceInformation");
deviceInfo.get(function(result) {
//fetch the device data
console.log("result = " + result);
}, function() {
console.log("error");
});
For those late to this party (like me), there is now this plugin, which gets SIM data for both Android and iOS devices: https://github.com/pbakondy/cordova-plugin-sim
EDIT: Spoke too soon. The plugin gets SIM info on both types of device, but on iOS, this does not include the phone number, which is not retrievable programmatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With