Ionic LocalNotifications not working on IOS


#1

I have an Ionic 2 app, that uses LocalNotifications plugin.

On android works very well. It has been in production for 2 months and now we need the ios version.
This is the code:

this.localNotifications.schedule({
    id: 1,
    text: '¡Hora de meditar!',
    at: scheduleDate,
    sound: this.isAndroid? 'file://audio/sound.mp3' : 'file://audio/sound.caf',
    every: "day"
});

This is used as a reminder. When the user activates the reminder, what he really does is to schedule a notification that is repeated every day at that time.

On Android all ok, no problems.

On IOS when you activate the reminder, it shows a black screen and the app closes, without saying anything. Is there any way to debug this? Since the localNotifications.schedule() method does not even return a promise, returns void.

Thank you very much in advance!!


#2

Solved. I was using (according Apple :slight_smile: ) an invalid Date.


#3

Share the valid date format…


#4

@Sujan12 It’s only a Date object:

/**
 *  I'm using ion-datetime wich always give me an string like '10:34'
 *  so, I get separately numbers and perform a new Date object.
 */

let hours: number = this.time.slice(0, this.time.indexOf(':'));
let minutes: number = this.time.substr(this.time.indexOf(':') + 1);
let scheduleDate = new Date();

scheduleDate.setHours(hours, minutes, 0);


// So, we schedule a notification using scheduleDate in the 'at' 
// attribute of the object wich will be send by params.

This is not my complete code. I used a custom provider to generate scheduleDate, and I validate if the platform is Android or IOS, among other things. I tried to simplify it to show an example.

Previously I was doing (the invalid Date object according apple, but it was working on Android):

var scheduleDate = new Date(this.timeFormatter.actualDateInYMD() + ' ' + this.time); // 2017/06/06 + ' ' + '10:43'