2

I run this code and simulate in browser, it just work perfectly which it'll remind me with notification for the exact time and date. but it didn't work when i simulate this using device (iOS).

LocalNotifications.requestPermissions();
this.$store.dispatch("listInterviews", { status: "incoming" }).then((res) => {
        for (const interview of res.data.data) {
          if (interview.status == 0 || interview.status == 1) {
            const iv_date = new Date(interview.date_time);
            const difference = (iv_date.getTime() - new Date().getTime()) / (1000 * 3600 * 24);
            if (difference < 1) {
              const now = new Date();
              const target = new Date(now.getFullYear(), now.getMonth(), now.getDate(), iv_date.getHours(), iv_date.getMinutes(), iv_date.getSeconds());

              LocalNotifications.schedule({
                notifications: [ 
                  {
                    id: interview.id,
                    title: 'Interview Invitation',
                    body: 'You have an upcoming interview tomorrow for ' + interview.post.title,
                    schedule: {
                      at: target,
                      allowWhileIdle: true, 
                    },
                  },
                ]
              }).then(() => {
                  console.log('Notification scheduled for interview ID ' + interview.id);
              }).catch((error) => {
                  console.error('Error scheduling notification for interview ID ' + interview.id + ':', error);
              });
            }
          }
        }
      });

Please help me, i dont know what to do anymore. been stuck this for days already.

  • i had this problem on android then remove LocalNotifications.requestPermissions(); from ngOnInit() and its work i dont know why ! – Majid Maddah Apr 04 '23 at 06:42

0 Answers0