简体   繁体   中英

JS does not recognize the plugin of cordova

I use HTML5 and PhoneGap ,

On application I have Local Notification.

Below is the code:

Local Notification

The Android implementation for local notification uses a similar interface as the existing iOS localnotification plugin. The plugin depends on the Android AlarmManager in combination with the Notification Bar .

Here my js:

function appReady() {
    alert('Start appReady');
    var LN = cordova.require("cordova/plugin/LocalNotification");
    alert('LN');
    LN.add({
        date: new Date(2012, 10, 11, 15, 20, 0, 0),
        message: "DeviceReady",
        ticker: "This is a sample ticker text",
        repeatDaily: false,
        id: 1
    });
    alert('End appReady');
}

the alert 'LN' does not appear.

here my plugin in config.xml file:

<cordova>
    <access origin="http://127.0.0.1*"/> <!-- allow local pages -->
    <access origin=".*"/>

    <log level="DEBUG"/>
    <preference name="useBrowserHistory" value="true" />
    <preference name="exit-on-suspend" value="false" />

    <plugins>
       ...
      <plugin name="LocalNotification" value="org.apache.cordova.plugins.LocalNotification"/>
    </plugins>
</cordova>

It looks like the JS does not know the plugin , can anyone help?

You should be using navigator.notification.alert

This can be found in the docs

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