【发布时间】:2017-06-04 05:17:53
【问题描述】:
我在一个小应用程序中使用了钛应用加速器,并使用 pushwoosh 作为通知服务器。
在我的 index.xml 中,我有以下内容:
<Alloy>
<!-- Anddroid Window -->
<Window id="index" platform="android">
<Require type="view" id="firstscreen" src="firstscreen"/>
</Window>
<!-- iOS Window -->
<NavigationWindow id="nav" platform="ios">
<Window id="win1" backgroundColor="white">
<Require type="view" id="firstscreen" src="firstscreen"/>
</Window>
</NavigationWindow>
</Alloy>
其次是index.js,比如我收到push,想把用户重定向到登录js,目的是从push自定义值打开对应的页面,但这里我做的很简单,只是为了测试。
if (OS_ANDROID) {
$.index.addEventListener('open', after_win_load);
$.index.open();
} else {
$.nav.addEventListener('open', after_win_load);
$.nav.open();
}
var pushwoosh = require('com.pushwoosh.module');
/*
* PUSHWOOSH
* */
pushwoosh.onPushOpened(function(e) {
var message = e.message;
var login = Alloy.createController('login').getView();
$.nav.open(login);
});
pushwoosh.initialize({
"application" : "XXXX-XXXXXX",
"gcm_project" : "XXXXXXXXXXX"
});
pushwoosh.registerForPushNotifications(
function(e) {
var pushToken = e.registrationId;
;
console.log('Push token ' + pushwoosh.getPushToken());
Alloy.Globals.resgisterId = e.registrationId;
},
function(e) {
var errorMessage = e.error;
console.log("Error during registration: " + e.error);
// alert('push error');
}
);
还有最后的 login.xml 和 login.js
<Alloy>
<Window id="login" >
<ScrollView scrollingEnabled="true" contentWidth="Ti.UI.FILL" disableBounce="true">
<!-- Here another view -->
</ScrollView>
</Window>
</Alloy>
//// login.js is simple :
var args = $.args;
console.log('hey boy');
收到推送通知时,点击它重定向到登录 js 我有以下错误:
[WARN] : Creating [object login] in a different context than the calling function.
[WARN] : Creating [object __alloyId48] in a different context than the calling function.
[ERROR] : Script Error {
[ERROR] : column = 2330;
[ERROR] : line = 1;
[ERROR] : message = "null is not an object (evaluating 'a.__views.login.add')";
[ERROR] : sourceURL = "file:///var/containers/Bundle/Application/ADE5F25A-17A4-4197-98C7-0781216545A3/myApp.app/alloy/controllers/login.js";
[ERROR] : stack = "Controller@file:///var/containers/Bundle/Application/ADE5F25A-17A4-4197-98C7-0781216545A3/myApp.app/alloy/controllers/login.js:1:2330\ncreateController@file:///var/containers/Bundle/Application/ADE5F25A-17A4-4197-98C7-0781216545A3/myApp.app/alloy.js:1:5254\nopenWin@file:///var/containers/Bundle/Application/ADE5F25A-17A4-4197-98C7-0781216545A3/myApp.app/xpng.js:1:283\nfile:///var/containers/Bundle/Application/ADE5F25A-17A4-4197-98C7-0781216545A3/myApp.app/alloy/controllers/firstscreen.js:1:3855";
[ERROR] : }
我不知道错误在哪里,你能帮我解决这个问题吗? 谢谢。
【问题讨论】:
-
注意:如果我将 Alloy.createController('login').getView().open() 放在 Pushwoosh 事件之外,我只能转到另一个页面
标签: push-notification titanium appcelerator appcelerator-titanium pushwoosh