pbakondy / cordova-plugin-sim

:cherries: A cordova plugin to get the device's SIM data (carrier name, mcc mnc, country code, telephonenumber, etc)
MIT License
163 stars 100 forks source link

How can I get carrier name to a string #8

Closed azn1viet closed 9 years ago

azn1viet commented 9 years ago
 function successCallback(result) {
        alert(result);//give me [object][object]
        alert(result['carrierName']);//give me 'Verizon'
        return result['carrierName'];//give me null
    }
    function errorCallback(error) {
        alert(error);
    }

   var dataCarrier =   window.plugins.carrier.getCarrierInfo(successCallback, errorCallback);

dataCarrier gives null, only alert works. How can I get carrier name to a string as dataCarrier

pbakondy commented 9 years ago

You want to use callbacks in a wrong way.

Try this code:

var dataCarrier;

function successCallback(result) {
    alert(result);//give me [object][object]
    alert(result['carrierName']);//give me 'Verizon'
    dataCarrier = result['carrierName'];
}

function errorCallback(error) {
    alert(error);
}

window.plugins.carrier.getCarrierInfo(successCallback, errorCallback);
azn1viet commented 9 years ago

thanks, it works.