简体   繁体   中英

cordova SMS plugin — javascript error

I am using cordova 3.6.3.
I am using following SMS plugin.

http://plugins.cordova.io/#/package/com.rjfun.cordova.sms https://github.com/floatinghotpot/cordova-plugin-sms/tree/master/docs

I have added plugin in following way :--
cordova plugin add com.rjfun.cordova.sms

My cordova app when loaded calls the following function doc_onload().

<body onload="doc_onload()">

Then this register the handler for "deviceready". When the device is ready this device ready function is called.

Now the problem inside the initApp() handler is that SMS plugin check does not display any alert message. I am able to get the alert --> "kk" .

But in the following check if (! SMS ) I did not get any display message. Neither if nor else got satisfied.

Even alert("end"); Does not get displayed inside initApp() event handler.

Please suggest why it is failing ?

function initApp()
{
    alert("initApp");
    // attach Fastclick handler
    FastClick.attach(document.body);

    alert("kk");

    if (! SMS )
    {
        alert( 'SMS plugin not ready' );
        return;
    }
    else
    {
        alert( 'SMS plugin Ok ' );
    }

    alert("end");

    //add SMS arrive listner handler
    document.addEventListener("onSMSArrive", processSMS(), false);


}

//function doc_onload(page_type)
function doc_onload()
{

   // Do some task
    alert("doc_onload");

    // add event handler for deviceready function
    document.addEventListener("deviceready", initApp(), false);

}

remove the brackets from 'initApp()' in

document.addEventListener("deviceready", initApp, false);

EDIT ** The above is just for semantics

I think you need to change !SMS to

typeof SMS === 'undefined'

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