Require.js с PhoneGap и Push-уведомления для iOs
Я создаю приложение с помощью Phonegap, Backbone.js и Require.js. Приложение реализует Push-уведомления PhoneGap. На данный момент загрузка скриптов в index.html выглядит следующим образом:
app.initialize();
index.js выглядит так:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
var pushNotification = window.plugins.pushNotification;
pushNotification.register(app.tokenHandler,app.errorHandler,{"badge":"true","sound":"true","alert":"true","ecb":"app.onNotificationAPN"});
},
errorHandler:function(error) {
//alert('in errorHandler');
//alert(error);
},
/*
*
* For iOS
*/
tokenHandler:function(status) {
//save the status to server
},
onNotificationAPN: function(event) {
//display alert
},
};
В tokenHandler я хочу вызвать модель, которую я определил как модуль Require.js. Итак, я интегрировал index.js с Require.js. Index.html стал таким:
Файл index.js теперь выглядит так:
define(function (require) {
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
var pushNotification = window.plugins.pushNotification;
pushNotification.register(app.tokenHandler,app.errorHandler,{"badge":"true","sound":"true","alert":"true","ecb":"app.onNotificationAPN"});
},
errorHandler:function(error) {
//alert('in errorHandler');
//alert(error);
},
/*
*
* For iOS
*/
tokenHandler:function(status) {
//save the status to server
},
onNotificationAPN: function(event) {
//display alert
},
};
return app;
});
В app.js я делаю:
... ... ...
require(['jquery', 'backbone', 'app/router', 'app/index'], function ($, Backbone, Router, Index) {
var router = new Router();
Index.initialize();
Backbone.history.start();
});
Проблема возникает в обратном вызове pushNotification.register (), который является app.onNotificationAPN. При загрузке index.js в качестве модуля Require это приводит к ошибке:
processMessage failed: Error
Когда я использую анонимную функцию вместо вызова app.onNotificationAPN, я также получаю ту же ошибку.
Каким должен быть правильный обратный вызов?