Parse.com push notifications lags and duplications - android

I integrated parse push notifications two days ago and it was working perfect. Today I made some more tests and I have huge lags, like parse notification was coming after 30 minutes instead of up to 5 seconds in previous days.
In addition I have 4 devices and I received 11 "Pushes Sent" instead of 4.
After a while of testing it starts to work normally, with only 4 "Pushes Sent", and after up to one minute instead of 30.
In addition I get 5 times the same push on my developer device, where I am installing and uninstalling app frequently and 4 times on the other dev device, so it sums up to magic number 11.
Is there are known issues with lags on Parse? I need responses up to one minutes. I though that it is reliable service. It was temporary situation or this is normal?

Every time you uninstall and install the app, you get a new installation object. Unfortunately, the old Installation object never goes away. What you need to do is to use some unique identifier for the device and just update the Installation if it exists.
For example, let's say that you're trying to do this on Android.
In your app, you can get the device's ANDROID_ID and save it to the installation: `
ParseInstallation.getCurrentInstallation().put("uniqueId",
Settings.Secure.getString(getApplicationContext().getContentResolver(),
Settings.Secure.ANDROID_ID));
Then you can have a cloud function that is triggered every time a new installation is saved:
Parse.Cloud.beforeSave(Parse.Installation, function(request, response) {
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.Installation);
query.equalTo("uniqueId", request.object.get("uniqueId"));
query.first().then(function(duplicate) {
if (typeof duplicate === "undefined") {
console.log("Duplicate does not exist,New installation");
response.success();
} else {
console.log("Duplicate exist..Trying to delete " + duplicate.id);
duplicate.destroy().then(function(duplicate) {
console.log("Successfully deleted duplicate");
response.success();
}, function() {
console.log(error.code + " " + error.message);
response.success();
});
}
}, function(error) {
console.warn(error.code + error.message);
response.success();
});
})
P.S. I've had that function for a long time and can't remember where I got it from, but I did not write it myself.

Related

Not getting the "MESSAGE_DELIVERED" Firebase event

I am trying to measure the latency between having a message exit Firebase Servers and being received on an Android app via the Firebase SDK. I have BigQuery integrated with my Firebase project, and have tried adding the following code:
// In the manifest:
<meta-data android:name= "delivery_metrics_exported_to_big_query_enabled"
android:value="true"/>
// In my Application object:
FirebaseMessaging.getInstance().setDeliveryMetricsExportToBigQuery(true);
The code seems to be exporting data to BigQuery. However, to calculate what I want I need timestamps for two different types of events associated to the same message id, "MESSAGE_ACCEPTED" and "MESSAGE_DELIVERED". Then, all I have to do is run a simple query that calculates the timestamp difference between those two.
My problem is: I can never seem to get the "MESSAGE_DELIVERED" variant for a given message id. I only ever get the "MESSAGE_ACCEPTED" side of the equation.
I am sending messages to the Android device via my own JavaScript app, and the request I make is like so:
app.get('/triggerAnt', function(req, res){
axios.post('https://fcm.googleapis.com/fcm/send', {
to:<TOKEN_FOR_DEVICE_GOES_HERE>,
notification:{
"title":"TESTNOTIFICATIONLATENCY",
"body":"TESTINGLATENCY"
},
fcm_options: {
analytics_label:<LABEL_HERE>
}
}, {headers: headers})
.then((response) => {
console.log(response.status);
}, (error) => {
console.log(error);
});
})
I would like to point out that the notification does effectively reach the device and I can open it too.
Is this delay on BigQuery's side or am I doing something wrong?
Thank you.

FCM push notification to reawaken app not effective while device slept

I ran into a problem with my flutter app where when it's minimized or the phone is put to sleep for too long (~5+ minutes), the app stops listening to firestore changes. One solution that I came across was to send push notifications to reawaken the device. While it seems to have fixed minimizing problem (the app now responds to changes), however it still suffers from the sleep problem. I noticed that the app still receives the push notifications, but the screen doesn't light up upon receiving them. Could that be why? Is there something that I can do to force the app to connect to the internet? I'm trying to think of a solution like sending a data payload to change the data locally, but I'm not sure if that's the optimal approach (or if it would even work). I'll post my firebase cloud function for sending messages on a doc update:
exports.sendLobbyNotificationTest = functions.firestore
.document("Lobbies/{lobbyCode}")
.onUpdate((change) => {
console.log("Checking for need of push notification...");
// const oldValue = change.before.data() || {};
const newValue = change.after.data() || {};
if (newValue.pushNotification == true) {
console.log("Found a push notification request for: ",
newValue.lobbyCode, "!");
// Set lobby back to false
admin.firestore().collection("Lobbies")
.doc(newValue.lobbyCode).update({
pushNotification: false,
});
return admin.messaging().sendToTopic(newValue.lobbyCode, message)
.then((result) => {
console.log("Message sent successfully: ", result);
// usersRef.where("lobbyCode", "==", newValue.lobbyCode).get()
// .then(function(querySnapshot) {
// querySnapshot.forEach(function(doc){
// })
// })
}).catch((err) => {
console.error("Error sending message: ", err);
});
}
console.log("No message needs to be sent!");
// return dummy value to prevent error
return 0;
});
const message = {
notification: {
title: "Bzzzt!",
body: "You've been buzzed!",
},
};
Is there something I'm missing?
Update: I think it just doesn't work because the phone is locked, once unlocked it begins to function normally.
I think figured out why from reading here: https://developer.android.com/training/monitoring-device-state/doze-standby.html (I had trouble finding this).
Basically if I use the right priority settings for android and ios (priority & content_available) it will bring the app out of idle and listen for changes.

Location tracking in background with PhoneGap

I'm trying to create very simple application that will get the current location of the device and post it to server every 15 minutes or so.
I'm using cordova-plugin-background-fetch ( https://github.com/transistorsoft/cordova-plugin-background-fetch ) and it works just fine awaking the app on about 15 minutes (or so), but the issue I'm facing is to get GPS coordinates.
I'm trying to get it using navigator.geolocation.getCurrentPosition and before I start BackgroundFetch, I make one test call with navigator.geolocation.getCurrentPosition to check if it works and have all the permissions. It is the same code as in example callback function and it works just fine on that first test call.
The problem I'm facing is that once BackgroundFetch awakes the application, in callback function navigator.geolocation.getCurrentPosition always fail (error code 3 - timeout expired).
I even tried to make it work with navigator.geolocation.watchPosition, but same issue. The first time I start it, it works. Once callback start it in background, it fails (again timeout expired).
I don't want to watch position all the time and drain the battery, I really need it only once in every 15-30 minutes.
Here is the code that I'm using and every help and suggestion is welcome!
Thank you!
BackgroundFetch.configure(function() {
console.log('[js] BackgroundFetch event received');
navigator.geolocation.getCurrentPosition(function(position){
console.log('we have location now');
$.post('https://www.example.com/api/location/', {
Lat: position.coords.latitude,
Lon: position.coords.longitude
}, function(data){
window.BackgroundFetch.finish();
}, 'json').fail(function(){
window.BackgroundFetch.finish();
});
}, function(error){
console.log('Error code: ' + error.code);
console.log('Error message: ' + error.message);
window.BackgroundFetch.finish();
}, {
enableHighAccuracy: false,
timeout: 20000,
maximumAge: 0
});
}, function(error) {
console.log('- BackgroundFetch failed', error);
}, {
minimumFetchInterval: 15
});
I thin the problem is the user has to physically accept geo location services one for them to be fetched

Phonegap- Facebook connect. Api calls doesn't fire any callback

I'm using Phonegap Build.
First of all, I need to say that this error doesn't happen if I try it with an administrator account of the app.
It only happen if a normal user tries to login in my app.
This is my code so far.
var facebookPermissions = ['public_profile', 'email', 'user_about_me', 'user_website'];
$(document).on('click', '#btnFacebook', function() { //click
facebookConnectPlugin.login(facebookPermissions, onFacebookLoginSuccess, onFacebookLoginError)
});
function onFacebookLoginSuccess(userData) {
alert("userData: " + JSON.stringify(userData));
facebookConnectPlugin.api('me', facebookPermissions,
function(result) {
alert("Result: " + JSON.stringify(result));
});
};
I'm the app's administrator and every work as expected... no trouble at all.
But if another user tries to login, the login works well, but there is no response for the api request.
Only the first alert is displayed
I also tried with this parameters
facebookConnectPlugin.api("/?fields=id,email",facebookPermissions,
facebookConnectPlugin.api("",facebookPermissions,
But nothing changes
I'm kinda lost here, and I dont know what else to try.
Your App may be in sandbox mode, activate it in the "Settings & Review" section
user_website needs to get reviewed. Without Login Review, it will only work for users with a role in the App.

Worklight 6.1 JSONStore call WL.JSONStore.init hangs in Android

I meet problem in JSONStore init function in Android. It will hang for about 10 minutes until then the JSONStore gives me the init result callback. This did occur only in Android and iPhone works fine. I can give the reproduce procedure:
Install my app in a 'clean' Android, which has not install the app before.
Successfully init the JSONStore by my arguemnts (I will attach the code below).
Then I re-install my app, note that I did't uninstall it but just replace it with a new build.
After replace I'm using the same auth try to init JSONStore, but it hangs....(Maybe will give the result callback at 10 minutes or longer, no error handlers trigger).
If a kill the app and re-launch it, then this time the JSONStore init very fast and works fine
I debug the App with inspect and I'm sure this is the problem that WL.JSONStore.init didn't give me result callback that hangs app. I don't know the reason why the first time need to consume so much time. Anyone meet the same issue as me?
var options = {password:pscd,localKeyGen:true};
var promise =
WL.JSONStore.init(data_collection, options).then(function(){
console.info("init json store successfully!");
return true;
}).fail(function (errorObject) {
console.info("init json store failed!" + errorObject);
return false;
});
return promise;
I just tried out the following code in the same 6.1 build that you have, and it is working fine for me on both the Android Emulator and a Nexus 4:
var data_collection = {people : {
searchFields : {name : 'string', age : 'integer'}
}
};
var pscd = "samplepassword";
var options = {password:pscd,localKeyGen:true};
var promise =
WL.JSONStore.init(data_collection, options).then(function(){
alert("init json store successfully!");
return true;
}).fail(function (errorObject) {
alert("init json store failed!" + errorObject);
return false;
});
return promise;
The only thing that might be different to your code is what your password or your data_collection variables are. Could you add more details regarding what data_collection is?

Categories

Resources