What could be the reason for local push notifications not working properly?

I was checking out the push notifications extension and I scheduled some notifications but they aren’t shown as scheduled and they only show at the same time immediately the app is reopened.

local function push_listener(self, payload, origin)
	-- The payload arrives here.
end

function init(self)
	push.set_listener(push_listener)
	local payload = '{ "data" : { "field" : "Some value", "field2" : "Other value" } }'
	id1, err1 = push.schedule(3000, "First Notification", "This is the first notification", payload)
	id2, err2 = push.schedule(6000, "Second Notification", "This is the second notification", payload)
	id3, err3 = push.schedule(9000, "Third Notification", "This is the third notification", payload)
end

Are you using the latest version of Defold and of the push extension? Is this on Android or iOS? I’d also take a look at device logs to see if something shows up in them.

1 Like

My apologies for the late reply. Here’s the code

local function push_listener(self, payload, origin)
	-- The payload arrives here.
	print("PAYLOAD")
	pprint(payload)
end

function init(self)
	push.set_listener(push_listener)
	local payload = '{ "data" : { "field" : "Some value", "field2" : "Other value" } }'
	id1, err1 = push.schedule(3000, "First Notification", "This is the first notification", payload)
	id2, err2 = push.schedule(6000, "Second Notification", "This is the second notification", payload)
	id3, err3 = push.schedule(9000, "Third Notification", "This is the third notification", payload)
	print("THESE ARE THE ERRORS")
	print(err1, err2, err3)
	print("THESE ARE THE IDS")
	print(id1, id2, id3)
end

And here’s a screen shot of the debug console

As you can see there are no errors and the scheduled notifications all have IDs but there’s an issue with the listener as it is supposed to output the payload which it doesn’t. Maybe the listener doesn’t receive anything or isn’t active.

Do the notifications trigger if the app is closed?

No, they are not triggered.

And logcat shows nothing? I don’t think it is required, but please try setting the push icons in game.project:

1 Like

The problem is still there.

Can you please try the example app that is included with the extension?

1 Like

I did just that and the notification scheduled for 30 seconds later was shown but the notification scheduled for 10 seconds later wasn’t shown. I think the issue is with my device not the extension itself. Thanks for your help.

One more question, whats the maximum possible time a local notification can be scheduled for?

I would say that it is related to Android OS and power saving functionality. There is no guarantee that notifications/alarms will be triggered exactly when scheduled and definitely not if there are many scheduled close together. And on Samsung devices there’s a limit to the number of notifications in the system in total.

1 Like

This is the most likely reason. Thanks a lot