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.
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.
Related
I'm using the Firebase plugin to create push notifications, and it works well. The idea is that I receive the notification - when I click on the notification the app opens with a dialog, and when you click on one of the options, you navigate to a page. However, when the app is minimized or closed and I receive a notification, the navigation doesn't works successfully. I'm using Nativescript 6.3.1 with Angular 8
onMessageReceivedCallback: (message: firebase.Message) => {
let meterNumber = message.data.meter;
let peid = message.data.peid;
let entid = message.data.entid;
this.mainService.listMeterNumbers(peid, true).subscribe((res) => {
let options = {
title: "Don't remind me about '" + message.data.meter + "' within -",
message: "",
cancelButtonText: "Cancel",
actions: ["1 Day", "1 Week", "1 Month", "1 Year"]
}
action(options).then((snooze)=> {
this.mainService.setMeterNotificationReminder(entid, snooze).subscribe(() => {
if(snooze !== 'Cancel') {
this.loading.navigateFromNotification = true;
this.loading.navigatedMeterNumber = meterNumber;
this.loading.navigatedMeterNumberParentEntityId = peid;
setTimeout(()=>{ // i've tried several different things here
this.ngZone.run(() => { // and here
this.loading.showNotificationList = false; // to do this - this was at first a .navigate(['newpage'], id)
});
}, 1000)
}
});
});
});
Please any help would be appreciated
There are two main states in which a push notification may be received by your application:
1.) Application is in Foreground.
2.) Application is in Background.
In the background state tho, there is a possibility that:
A. Your app is not in view (hence in the background) but is not closed and still fully running. Eg. you are on a different app.
B. Your app is not in view (still background) but is fully closed and not fully running. Only the Push Notification subscription service is running.
In your case, the reason why your code handling on onMessageReceivedCallback doesn't fully work is because the app is closed (case B) and thus some context of the code here are undefined.
For example, your this.mainService is undefined and this service might only be constructed when you run the application or the application is open.
There are various work around for this, but main thing is that on your onMessageReceivedCallback you should separate your code handling by:
if (message.foreground) {
... do stuff when app is foreground ...
}
else {
... handling if app is closed or in background. this code is executed when the user taps on the notification ...
}
You'll have to route the user to the correct page in onMessageReceivedCallback. Probably in an 'app loaded' event.
You can get more ideas here.
I watched a tutorial on youtube and I did exaclty like the tutor said.I even copied his code from the source file he provided and I get an error...but if I run his project then it works.
Why these things happens?
I have a segmented component and when I change it from login to register this code runs:
#IBAction func signinSelectorChange(_ sender: UISegmentedControl) {
// Flip the boolean
isSignIn = !isSignIn
// Check the bool and set the button and labels
if isSignIn {
signinLabel.text = "Sign In"
loginButton.setTitle("Sign In", for: .normal)
}
else {
signinLabel.text = "Register"
loginButton.setTitle("Register", for: .normal)
}
}
when I switch I get this error message :
2017-04-27 21:30:34.932 FIREBASE - Read and Write[38283] [Firebase/Analytics][I-ACS023012] Firebase Analytics enabled
fatal error: unexpectedly found nil while unwrapping an Optional value
what is wrong?
thank you
So I'm using Appium to test an iOS app. I've written my tests in javascript and am using Mocha as the testing framework. Everything runs fine except for trying to get an example test to pass:
it('should find sign up label', function () {
return driver.waitForElementByName('_signUpLabel', 3000)
.then(function (el) {
el.text().should.equal('Sign up with...');
});
});
And this is the app's code in question:
_signUpLabel = [[UILabel alloc] init];
[_signUpLabel setAccessibilityIdentifier:#"_signUpLabel"];
...
[_signUpLabel setText:#"Sign up with..."];
[view addSubview:_signUpLabel];
The iOS simulator loads, then the app loads, then the login view loads just fine with the element in view, yet the error I receive is: AssertionError: expected { state: 'pending' } to equal 'Sign up with...'
I can see that Appium has found an element through its logging:
> CALL waitForElementByName("_signUpLabel",3000)
> CALL elements("name","_signUpLabel")
> POST /session/:sessionID/elements {"using":"name","value":"_signUpLabel"}
> RESPONSE elements("name","_signUpLabel") [{"ELEMENT":"0"}]
> RESPONSE waitForElementByName("_signUpLabel",3000) {"ELEMENT":"0"}
> CALL element.text()
> GET /session/:sessionID/element/0/text
So can someone tell me where I'm being stupid?
Is el.text() sync or async? The pending suggests you might need to wait for a result?
I'm currently building an android application using ionic/ngcordova. I'm at the point of implementing push notifications. I've implemented push notifications as a service which is injected at app.run(function(){..}) stage. The registration part works and I receive a callback containing the regid. Also, when the application is in the active state, the event is raised and the notification is received.
The problem I'm having is that when the application goes into the background, the notifications are not received at all. I would expect that a local notification would be raised when the app isn't running or something similar, but absolutely nothing happens, which is weird.
I've trawled the web for the last couple of days looking for a solution but I've been unable to find anything which kind of indicates to me that it should just work.
The following is my notificationService.js inside my app
app.factory('notificationService', ['$cordovaPush', function($cordovaPush){
var dataFactory = {};
//
// When the device is ready and this service has been plumbed in...
document.addEventListener("deviceready", function(){
console.log("initializing push notifications...");
_register();
}, false);
//
// Registers the device for push notifications...
var _register = function(){
var config = {};
if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
// TODO: centralise this value as it can change...
config = {
senderID: "448168747432",
ecb: "onNotificationGCM"
};
}else {
// iOS
config = {
"badge":"true",
"sound":"true",
"alert":"true"
};
// Can add the following property to the config object to raise a callback with the information if need be...
// "ecb": "onNotificationRegisterAPN"
}
$cordovaPush.register(config).then(function(result){
//
// Typically returns "ok" for android and devicetoken for iOS
console.log(result);
});
};
window.onNotificationGCM = function(result){
console.log(result);
/*
I get called when the app is in the foreground, but nothing happens when the app is in the background.
*/
};
dataFactory.register = _register;
return dataFactory;
}]);
If it helps, I'm using PushSharp via a .net application in order to deliver the notifications. Any help would be greatly appreciated.
UPDATE: I'm using the following frameworks/libs:
Ionic Framework 1.2.14-beta6
Cordova 4.2.0
PushPlugin
For anyone else who's been pulling their hair out for a couple of days like I have, the solution was really simple...I was missing two properties in my Pushsharp QueueNotification request. So using the example given on the PushSharp github repo here: https://github.com/Redth/PushSharp#sample-code
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("DEVICE-REGISTRATION-ID-HERE").WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}"));
Needs to be updated to add the missing properties:
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("DEVICE REGISTRATION ID HERE")
.WithJson(#"{""alert"":""This is the future"",""badge"":7,""sound"":""sound.caf"",""title"":""Status Bar title"",""message"":""Some text you want to display to the user""}"));
Otherwise if your app happens to be developed using Cordova and its not currently in the foreground, nothing, repeat nothing will happen.
Tip my hat to gdelavald with his comment on PushPlugin for pointing me in the right direction here:
https://github.com/phonegap-build/PushPlugin/issues/212
I am just starting to build a new Meteor app. The only thing I have done so far is add one Collection. It will start, run fine for about 5 minutes, and then give me the error message "Failed to receive keepalive! Exiting."
What is failing to receive keepalive from what? I assume this has something to do with Mongo since that is the only thing I have added. Googling the error message turns up nothing except Meteor sites that are just showing this error message instead of the their app.
My MongoDB collection already had data in it that was not created by Meteor and it is over 4GB if that makes any difference.
This is the complete app.
pitches_sum = new Meteor.Collection( 'pitches_sum' );
if (Meteor.is_client) {
Template.hello.greeting = function () {
return "Welcome to my site.";
};
Template.hello.events = {
'click input' : function () {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
console.log("You pressed the button");
}
};
}
if (Meteor.is_server) {
Meteor.startup(function () {
console.log( '**asdf**' );
});
}
If I comment out the pitches_sum = new Meteor.Collection( 'pitches_sum' ); line, then I don't think I will get the error message any more.
This was being caused by my large data set and autopublish. Since autopublish was on, Meteor was trying to send the whole 4GB collection down to the client. Trying to process all the data prevented the client from responding to the server's keep alive pings. Or something to that effect.
Removing autopublish with meteor remove autopublish and then writing my own publish and subscribe functions fixed the problem.