Local notifications push.get_all_scheduled() (DEF-2747) (SOLVED)


#1

After my failed with non-consumable purchases “bug” that was not a bug =) I afraid to set a bug status to new posts =)

And now it just a question.
How push.get_all_scheduled() should woks?

I have next behavior:

  1. open an app;
  2. register new notification;
  3. check registered notifications using push.get_all_scheduled() – it’s just 1 that we registered;
  4. close an app (fully close);
  5. open an app;
  6. check registered notifications using push.get_all_scheduled() – 0 notification, but my notification from point 2 will alert in time.

That mean that I have no possibility to remove old notification after app was restarted.

Is it by design or a bug? (I tested it only on android)

My testing script:

local console = require("defcon.console")
local standart_prefix = '{"data" : {"type" : "'
local standart_postfix = '"}}'
local test =
{
  time = 60,
  title = "Test",
  alert = "test?",
  payload = standart_prefix.."test"..standart_postfix
}

local function push_listener(self, payload, origin, activated)

end

function init(self)
	push.set_listener(push_listener)
	console.register_command("nlist", "notifications list", function(args, stream)
      local all_n = push.get_all_scheduled()
      local str = "List:\n"
      for i, v in pairs(all_n) do
        local jstype = json.decode(v.payload)
        str = str..i.." = "..jstype.data.type.."  seconds = "..v.seconds.."\n"
      end
      return str
    end)
    
    console.register_command("nadd", "register one", function(args, stream)
      push.schedule(test.time, test.title, test.alert, test.payload, {})
      return "done"
    end)
end


Can you make Defold Extensions open source?
#2

Hmm, not sure. Local notification support was implemented by @sven. I’ll give Sven a chance to answer (if he knows the answer ) before I spend some time investigating.


#3

Short answer is that there is a discrepancy between the iOS and Android implementations in this regard, on Android it’s not currently possible to list scheduled notifications from a previous run. :confused:

If I remember correctly, there is no reliable (or at least wasn’t at the time of implementation) way to list notification alarms we set on Android, in Java. I’ll add an issue for this so we can give this another look, it might be possible for us to serialise this information between runs.

(Some more in-depth info; Internally the notifications information are kept on the C++ side, but the are never serialised and are simply lost between restarts. While on iOS we don’t need to keep track of this ourselves, we can ask the OS to just give us a list of pending notifications.)


#4

So a quick solution for Android would be to do the book keeping of notifications on the Lua side?


#5

Sadly no, the notification list (C++ side) is lost between runs, so trying to cancel a notification with a certain ID that isn’t in the list will result in an error. :frowning: I think we need to fix this in engine if possible.


#6

yes, it’s not helped (
I tried to save ids but it doesn’t work.

I hope for a fix, thank you.

I broke everything I touched =)


#7

Maybe you have any news or estimates? (just want to know should I remove notifications in android build or not)

UPD: we continue working on free to play version and this issue is actual again for us (we have many issues with this)


#8

Up the topic
There is chance, what we can cancel local notifications soon? In this way they are not usable now

I need in local notifications for my games, but have to disable android pushes now


4321 Puzzle
#9

This is not something we have planned to fix short term I’m afraid. During the coming two weeks we’re going to work on our roadmap and backlog for the coming months. I will be giving everyone a chance to suggest your top prio missing features or bugs so that we can incorporate them in our plans. A separate post will be made regarding this, most likely next week.


#10

Solved in 1.2.129