我正在开发一个需要推送通知功能的煎茶触摸应用程序。根据 sencha 文档,我知道他们不支持 Android 推送通知。所以我试图将我的项目与 Phonegap 3.0 集成。对于推送通知,我正在使用此插件 https://github.com/hollyschinsky/PushNotificationSample30/
该演示在获取注册 ID 时运行良好,我可以向该注册 ID 发送推送通知。但问题是当我尝试将我的 sencha 应用程序集成到这个演示推送插件时,我没有得到 reg id
我的 index.html 看起来像这样
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>crmapp</title>
<script id="microloader" type="text/javascript" src="touch/microloader/development.js"></script>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="PushNotification.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</head>
<body>
<div id="appLoadingIndicator">
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>
并从我的 app.js 文件中调用 js/index.js 文件中的推送通知功能,它看起来像这样
Ext.application({
name: 'WinReo',
requires: [
'Ext.MessageBox',
],
views: [
'Login',
// 'MainMenu',
'CrmFooter',
'CrmHead',
],
controllers:[
'Login',
'Main',
'Task',
],
models: [
'Event',
"Task"
],
stores: [
'Events',
'EventsDueListStore'
//'Contactsstore'
],
icon: {
'57': 'resources/icons/Icon.png',
'72': 'resources/icons/Icon~ipad.png',
'114': 'resources/icons/Icon@2x.png',
'144': 'resources/icons/Icon~ipad@2x.png'
},
isIconPrecomposed: true,
startupImage: {
'320x460': 'resources/startup/320x460.jpg',
'640x920': 'resources/startup/640x920.png',
'768x1004': 'resources/startup/768x1004.png',
'748x1024': 'resources/startup/748x1024.png',
'1536x2008': 'resources/startup/1536x2008.png',
'1496x2048': 'resources/startup/1496x2048.png'
},
launch: function() {
Ext.fly('appLoadingIndicator').destroy();
app.initialize(); // **Please see this line**
},
onUpdated: function() {
Ext.Msg.confirm(
"Application Update",
"This application has just successfully been updated to the latest version. Reload now?",
function(buttonId) {
if (buttonId === 'yes') {
window.location.reload();
}
}
);
}
});
这是 index.js 文件
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
var pushNotification = window.plugins.pushNotification;
pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"675077458226","ecb":"app.onNotificationGCM"});
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
// result contains any message sent from the plugin call
successHandler: function(result) {
alert('Callback Success! Result = '+result)
},
errorHandler:function(error) {
alert(error);
},
onNotificationGCM: function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Regid " + e.regid);
alert('registration id = '+e.regid);
document.write(e.regid);
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = '+e.message+' msgcnt = '+e.msgcnt);
break;
case 'error':
alert('GCM error = '+e.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
};
我不确定这是调用此函数的方式,根本无法访问该函数,没有获取注册 ID.. 请指导我正确的方向.. 这是从 sencha touch 调用 phonegap 函数的方式吗?遇到问题,请帮我解决这个问题,谢谢..