简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM