Reputation: 23
I use titanium appcelerator for a little app, with pushwoosh as notification server.
On my index.xml i have following :
<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>
secondly index.js, where i receive push and want to redirect user to login js for example, the aim is to open corresponding page from push custom value, but here i do it simple, just for test.
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');
}
);
And the last login.xml and 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');
When receiving push notification, and click on it to redirect to login js i have following error :
[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] : }
I have no idea where the error is, could you please help me to resolve this? Thank you.
Upvotes: 1
Views: 577
Reputation: 3539
You just need a little change in code:
pushwoosh.onPushOpened(function(e) {
var message = e.message;
var login = Alloy.createController('login').getView();
OS_IOS ? $.nav.openWindow(login) : login.open();
});
For iOS - you need to use openWindow() method of NavigationWindow, and for Android it's simple open() call.
Note:
Since you mentioned that you want to navigate user to different section of the app, so you will need to take care that your NavigationWindow exists before you open another window in it.
That's why you are getting that null error because when you receive notification and you tap on it, it opens the app and run this pushwoosh.onPushOpened method, and till this time you don't have any NavigationWindow created. So you need a different flow for navigation to different sections.
After tapping on notification, if your app is running in background mode, then I believe you won't get this error because you already have a NavigationWindow created,
But if your app is in killed state and you receive and tap on notification, then you will get this error because your app has no NavigationWindow created yet (that's why you see the different context written on console).
So to do what you want, you will need to create a different flow to handle the scenario of opening the app's login window upon receiving a push message. (in simple words you'll still need to create NavigationWindow and open login window in it or a different approach).
I hope you now have the clear idea of what actually causing your app to show that error.
Upvotes: 1