Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic get user's phone number

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'.

like image 739
Lad Avatar asked Jan 04 '15 18:01

Lad


People also ask

What is ionic native core?

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.


2 Answers

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");
    }); 
like image 97
shellakkshellu Avatar answered Oct 11 '22 23:10

shellakkshellu


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.

like image 25
see sharper Avatar answered Oct 12 '22 00:10

see sharper