I am trying to use Parse Cloud Jobs to trigger a download in my app. The documents suggest that I should use content-available to send this background push that would not be visible to the user, but to the app.
I tried implementing it as follows:
Parse.Cloud.job("sendAlert", function(sendAlert) {
// Set up to modify user data
Parse.Push.send({
data: {
content-available: 1,
}
}, {
success: function() {
// Push was successful
},
error: function(error) {
// Handle error
}
});
});
I also want to schedule it to run every 15 min.
With the expected behavior that it runs every 15 minuites, and sends a background push notification to the app.
However, when I try to deploy it, I get
Update failed with Could not load triggers. The error was Uncaught SyntaxError: Unexpected token - in main.js:5
and when I try to schedule it, it doesn't show up, most likely due to the error.
Change to:
data: {
"content-available": 1,
}
It was trying to do some subtraction without the quotes.
Related
Hi i am using azure process to send the push notification to windows 10
above version hybrid app and i use the below code to send the notification
https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-
mobile-cordova-get-started-push
i got this document there
pushRegistration.on('registration', function (data) {
this method is not firing is there any process to register before to send
notification
You have to implement a registerForPushNotifications method an call it every time user opens the App:
var pushRegistration = null;
function registerForPushNotifications() {
pushRegistration = PushNotification.init({
android: { senderID: 'Your_Project_ID' },
ios: { alert: 'true', badge: 'true', sound: 'true' },
wns: {}
});
If pushRegistration.on is not called, maybe registration is not complete or there is some error.
Create a breakpoint or print some message in:
pushRegistration.on('error', handleError);
And take a look if it's something wrong.
Also, you can check if there is some missing configuration following the Notification Hubs Diagnosis guidelines: https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-fixer
I'm running parse-server on ubuntu and can't seem to get push notifications working when sent in cloud code.
Push's work when using a REST api call (passing master key) but don't work when cloud code calls them.
What's interesting is that the cloud code Parse.Push() method returns a success and thus no error message.
My hypothesis is that this is a configuration problem, and the Parse.Push() method is referencing somethign I have incorrectly configured on the server.
here is my cloud function. This call works when sent via REST. and the success callback in cloud is always called.
Parse.Push.send(
{
// where: pushQueryClient,
channels: ["user_tkP7gurGzc"],
data:
{
alert: pushTextClient
}
},
{
success:function(){
console.log("push sent");
},
error: function(error){
console.log("push failed");
console.dir(error);
},
useMasterKey: true});
i think you have an issue with the useMasterKey parameter.
Please try to use this code in order to send the push notification:
Parse.Push.send({
where: whereQuery,
data: {
alert: {
title: request.params.title,
body: request.params.body
},
type: request.params.type,
sound: 'default'
}
}, {
useMasterKey: true
}).then(function() {
response.success();
}, function(error) {
response.error("Push failed " + error);
});
In this code i use Promises which is the best practice and also wrap useMasterKey in a separate object
I am trying to use push notifications on the iphone emulator, but I am not having any success, I am using the example code:
var deviceToken = null;
// Check if the device is running iOS 8 or later
if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
Ti.API.log("identificada versão 8");
// Wait for user settings to be registered before registering for push notifications
Ti.App.iOS.addEventListener('usernotificationsettings', function registerForPush() {
Ti.API.log("Notifications config set");
// Remove event listener once registered for push notifications
Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush);
Ti.Network.registerForPushNotifications({
types : [Ti.App.iOS.NOTIFICATION_TYPE_BADGE, Ti.App.iOS.NOTIFICATION_TYPE_ALERT, Ti.App.iOS.NOTIFICATION_TYPE_SOUND],
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
});
// Register notification types to use
Ti.App.iOS.registerUserNotificationSettings({
types: [
Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
]
});
}
// For iOS 7 and earlier
else {
Ti.Network.registerForPushNotifications({
// Specifies which notifications to receive
types: [
Ti.Network.NOTIFICATION_TYPE_BADGE,
Ti.Network.NOTIFICATION_TYPE_ALERT,
Ti.Network.NOTIFICATION_TYPE_SOUND
],
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
}
// Process incoming push notifications
function receivePush(e) {
alert('Received push: ' + JSON.stringify(e));
}
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
deviceToken = e.deviceToken;
subscribeToChannel();
}
function deviceTokenError(e) {
alert('Failed to register for push notifications! ' + e.error);
}
and none of the registerForPushNotifications() callbacks are being fired, the success, the error, or the callback are not being called, and I am having a hard time solving it, I searched a bit on the web, the solutions where:
to turn off the liveView, but it did not solve my problem,
testing on a real iphone didn't help;
Check all the pushnotifications configurations on the appcelerator dashboard, and everything was fine.
I still can't find a solution.
Push notification only works on device.Push Notifications iOS simulator
Configuring push services for iOS devices
As suggested by Jagu and Danny, there is no way to test the Push Notifications on simulator/emulator.
But also remember to turn off LIVE VIEW when you test it on physical device, otherwise you may not get device token.
My app has notifications based on zip code and channels.
When a user changes zip code the app updates the Installation with the new zip.
In my beforeSave on Installation I grab the new zip and subscribed channels and search for relevant notifications.
Then I need to send the notifications as pushes back to that installation.
Two questions:
Can I just push to the Installation object that came into the beforeSave as such:
return Parse.Push.send({
where: request.object
data: data
})
or do I have to do an Installation query for that objectId?
I can't just push the notification object. I need to configure the data. If there are multiple notifications (not likely but possible) what's the best way to send multiple pushes back to that installation (assuming I don't want to put them all in one push)?
I can't send the pushes from a for loop. Can I do something like this:
return notificationQuery.each().then( function(notification) {
//configure push from that notification
return Parse.Push.send ... etc
})
Thanks!
You can send Push notifications in parse based on channels or where(query) but not both.
So you can do a query on Installation class with channel and zipcode:
var query = new Parse.Query(Parse.Installation);
query.equalTo('channels', 'Indians');
query.equalTo('zipcode', "345678");
Parse.Push.send({
where: query,
data: {
action: "com.example.UPDATE_STATUS"
alert: "Ricky Vaughn was injured in last night's game!",
name: "Vaughn",
newsItem: "Man bites dog"
}
}, {
success: function() {
// Push was successful
},
error: function(error) {
// Handle error
}
});
Hope this helps.
I'm using the Facebook SDK to auth a user, and trying to save the user's email to the record after authenticating. However, I keep getting an error on the save call.
The code in question:
Parse.FacebookUtils.logIn({
access_token: authResponse.access_token,
expiration_date: expire_date.toISOString(),
id: response.id
},
{
success: function(user) {
console.log("success!");
user.set({"email":response.email});
user.save();
window.App.navigate("#myplaces", {trigger:true});
},
...
That user.save() call returns error occurred: http://www.parsecdn.com/js/parse-1.1.14.min.js:1: TypeError: 'undefined' is not an object.
According to the docs, I have to be in an authentication call (".logIn", etc.) to perform save(), so I'm wondering if this still works with Parse.FacebookUtils.logIn. Seems like it should.
Ideas as to why this isn't working? The ideal behavior is to log the user in, retrieve information from the FB response, and save that back to the user record on Parse.
Thanks!
Justin
Not sure about this but I had the same problem in Cloud Code and I used success/error callbacks when calling save(...):
user.save(null, {
success: function(){
// Code
},
error: function(){
// Code
}
});
See also here: https://parse.com/questions/saving-a-relation-on-the-current-user