storing notification ID

Hi there,

Im using local notifications as a sort of alarm in my app. So that I can cancel the scheduled notifications in different sessions, I would like to store the notification ID in a file. I tried using json to convert the table to string but I get the following error: 

“type ‘userdata’ is not supported by JSON”.

Has anyone encountered the same problem? Is there a way to save the NotificationID so I can use it later on in different sessions??

I’m using corona build: 2013.2100, and the code to replicate the error is the one bellow:

local futureTime = os.date( "!\*t", os.time() + 10000 ) local options = { alert = "this is the alert message", custom = {abc="custom content"}, } local notificationID = system.scheduleNotification( futureTime, options ) local json = require("json") local result,text = pcall( json.encode, notificationID) display.newText({ text=tostring(result) .. "\n" .. text, x=display.contentCenterX, y=display.contentCenterY, fontSize=30, width=display.contentWidth \* 0.8 })

“userdata” is basically a C structure representing the current in-memory object.  Lua can read data values in and out of the structure, but because it’s just a memory address, there is no way to save it.  This is a frequently asked for feature, but there is currently no way to store notifications and be able to get back to them.

Rob

So, if you create a system notification, there is not way to cancel it later after the user left the app?

E.g:

  1. I created a notification

  2. User quit the game

  3. User entered again in the game

  4. I need to cancel the notification because the user went back in the game again and my notification now will have no meaning

Thanks for the reply Rob!

So, heres the solution Im thinking on using (if anybody comes back to this thread later):

 1. instead of storing notification ID, I will store in a file with json all information I used to create the notifications (ie. time its supposed to fire, alarm message and etc)

 2. Whenever I need to cancel a notification, even if it is only one, I will cancel them all (to cancel all I dont need their IDs)

 3. After canceling them all, I will then use the stored information to re-create all other notifications that were not meant to be cancelled.

That seems reasonable.

hey 

good idea!

“userdata” is basically a C structure representing the current in-memory object.  Lua can read data values in and out of the structure, but because it’s just a memory address, there is no way to save it.  This is a frequently asked for feature, but there is currently no way to store notifications and be able to get back to them.

Rob

So, if you create a system notification, there is not way to cancel it later after the user left the app?

E.g:

  1. I created a notification

  2. User quit the game

  3. User entered again in the game

  4. I need to cancel the notification because the user went back in the game again and my notification now will have no meaning

Thanks for the reply Rob!

So, heres the solution Im thinking on using (if anybody comes back to this thread later):

 1. instead of storing notification ID, I will store in a file with json all information I used to create the notifications (ie. time its supposed to fire, alarm message and etc)

 2. Whenever I need to cancel a notification, even if it is only one, I will cancel them all (to cancel all I dont need their IDs)

 3. After canceling them all, I will then use the stored information to re-create all other notifications that were not meant to be cancelled.

That seems reasonable.

hey 

good idea!