在此link之后,我正在使用React.js
作为前端创建Cordova(Android)应用程序,一切都在运行,但是不知道在脚本中的何处放置或调用Cordova插件方法。
这是我开始时叫cordova.plugins.notification.local.schedule
的时候所调用的deviceready
但是在npm build
期间返回Cordova is undefined
错误,那么如何在脚本中使用cordova插件?
import React from "react";
import ReactDOM from "react-dom";
import "./css/main.css";
import App from "./App";
import registerServiceWorker from "./registerServiceWorker";
import { Router, Route } from "react-router-dom";
import createHashHistory from "history/createHashHistory";
let history = createHashHistory();
const startApp = () => {
window.document.addEventListener("deviceready", () =>
ReactDOM.render(
<Router history={history}>
<Route path="/" component={App} />
</Router>,
window.document.getElementById("root")
)
);
registerServiceWorker();
};
if (window.cordova) {
document.addEventListener("deviceready", showAlert, false);
function showAlert() {
cordova.plugins.notification.local.schedule({
id: 1,
title: 'My first notification',
text: 'Thats pretty easy...',
attachments: ['file://img/screen-ldpi-landscape.png'],
foreground: true,
vibrate: true
});
}
startApp();
} else {
startApp();
}