In my application the user creates an alarm which uploads an object to parse as well as schedules a push notification for the time that they select. I had it working yesterday but for some reason today, right after the user creates the alarm the notification is triggered. I can't figure it out, I don't remember changing anything.
Here is my code to create the notification:
PFUser *user = [PFUser currentUser];
PFObject *alarm = [PFObject objectWithClassName:@"Alarm"];
alarm[@"Active"] = @YES;
alarm[@"Bounty"] = IntNumber;
alarm[@"ActionComplete"] = [NSNumber numberWithInt:0];;
alarm[@"Time"] = _alarmTime;
alarm[@"User"] = [PFUser currentUser];
NSLog(@"%@",_alarmTime);
NSString *dateString = [NSString stringWithFormat:@"%f",[_alarmTime timeIntervalSince1970] * 1000];
NSString *clientId = [[PFUser currentUser] objectId];
NSLog(@"%@",dateString);
alarm[@"aString"] = dateString;
[alarm save];
NSString *objectID = [alarm objectId];
[PFCloud callFunctionInBackground:@"sendSilentPush"
withParameters:@{
@"clientId":clientId,
@"alarmTime":dateString,
@"alarmTimeDate":_alarmTime,
}
block:^(id object, NSError *error) {
}];
And this is my cloud code:
Parse.Cloud.define("sendSilentPush", function(request,response){
//Get user Id
var recepeintId = request.params.clientId;
var alarmTime = request.params.alarmTime;
var alarmTimeDate = request.params.alarmTimeDate;
//Get User hook using the ID using a query on user table
var userQuery = new Parse.Query('_User');
userQuery.get(recepeintId, {
success: function(user) {
// object is an instance of Parse.Object.
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('deviceType', 'ios');
//Send a push to the user
Parse.Push.send({
where: pushQuery,
"data" : { "content-available": 1,
"sound": "",
"extra": { "Time": alarmTime }
}
}).then(function() {
response.success("Push was sent successfully.")
}, function(error) {
response.error("Push failed to send with error: " + error.message);
});
},
error: function(user, error) {
// error is an instance of Parse.Error.
}
});
});