我在 cordova 应用程序中处理 OneSignal PushNotification 时遇到问题。我的目的是从任何 Controller 打开显示页面,每个页面都有特定的 Controller 。每当通知到来时都会做同样的事情,打开显示页面。我的代码在这里:
index.html
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
var notificationOpenedCallback = function(jsonData) {
//do some thing
};
window.plugins.OneSignal
.startInit("xxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxx")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
}
Controller
app.controller('startController', function ($scope, $http) {
var notificationOpenedCallback = function (jsonData) {
$scope.myNavigator.pushPage('form/displaypage.html');
};
window.plugins.OneSignal //get error : Uncaught TypeError: Cannot read property 'OneSignal' of undefined
.startInit("xxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxx)
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
});
如何将windos.plugins.OneSignal
放入 Controller 中?
最佳答案
对于cordova应用程序,您需要首先添加OneSignal插件。在终端中,在 cordova 应用程序的根目录中,执行
cordova 插件添加 onesignal-cordova-plugin
如果您想将此插件保存到 config.xml
中,请将 --save
标志添加到命令末尾。如果您使用共享版本控制,这会派上用场。
这将安装并注册插件。然后,您应该重建项目并在您的设备上重试。
有关使用 Cordova SDK 设置的更多信息,请访问 here
关于javascript - AngularJS Controller 中的 OneSignal 推送通知句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40960379/