How To Use Os.date() To Schedule App To Turn Off?

Hi, all.

I tried using the simple timer.performWithDelay, but it pauses when the device is suspended with the “blocked screen” mode. Can someone help with that? I want the app user to activate the os.date() timer through a button and I want him to have a button to turn it off as well.

 

I tried using the following

[lua]

local timer;

function start(e)

  timer = os.date("!*t", os.time() + 60);

  print(timer);

end

someObject:addEventListener(“tap”, start);

 

function verifyTimer()

 if(timer == 60)then

  os.exit();

 end

end

Runtime:addEventListener(“enterFrame”, verifyTimer);

[/lua]

It seems “timer” has not a printable value…

 

Please, help.

Thanks. 

 

 

 

I tried the system notifications API, but I got no success…

Please!

Hi @WilerJr,

I’m not sure I understand the intention here. You want to “force close” the app using a timer or a local notification? As described in the “os.exit()” API documentation:

 

“It is highly recommended that you do not call this function in a release version of your application. Calling os.exit() terminates the application process immediately, which can be interpretted by an app reviewer as a crash, causing your application to be rejected.”

 

So, I don’t recommend you use “os.exit” at all. This seems like it would be strange behavior from a user standpoint… like a ticking time bomb before the app terminates? Maybe I’m not understanding the overall goal here.

 

In regards to Local Notifications, did you reference this tutorial?

http://www.coronalabs.com/blog/2012/06/05/local-notifications-guide-ios/

 

Sincerely,

Brent Sorrentino

Hi, Brent, and thanks for the answer.

My overall goal is the following: I want the player to choose a certain number of minutes to define in how much time he wants the game to exit, get it?

The player is going to decide that, so I think he won’t think that’s a crash.  

Hi WilerJr,

I see what you mean, but it’s not so much the user that I’m worried about (thinking it’s a crash)… it’s the marketplace “gatekeepers”. This will likely be considered an undesirable feature, and your app will be rejected.

 

Why not just kick the user back to a title screen or something? You can do that by simply running a timer and controlling it (pausing it, restarting it, etc.) during various system events if necessary.

 

Brent

That’s sad to know…

 

I need the game to turn off automatically to save user’s battery. What I mean is that the user may not be paying attention to the device (I hope you understand) to close the app and his device’s battery will be affected. I want the app to play its songs and count the minutes the user chooses even if the device is suspended; it’s a feature I really need inside my app. Do you understand that?

 

Thanks.

Ah, I see… well then, if the reviewer understands this, hopefully it will pass approval. In regards to testing the local notifications, did you follow the entire process in the URL I mentioned above? And more info here: http://docs.coronalabs.com/api/library/system/scheduleNotification.html

 

This should set up a local notification after a specific time (as you want) and then you can trigger the app exit using “os.exit()”. I mainly wanted to bring to you attention that a forced app exit is generally not considered “usual practice”, so it might raise flags on the approval side… but maybe not. :slight_smile:

I hope they understand! :smiley: haha

 

Yes, Brent. I have understood the scheduleNotification API, but I need a method where my users will have choice to enable the shutdown schedule timer and, if they want, to disable the timer, do you get it?

I don’t know there’s a way to do that, but I’m trying. I’m asking for help because I don’t want to keep trying to discover a thing which has no way to be implemented, then I can focus on other features of my app.

 

Thanks. :slight_smile:

Is the “system.cancelNotification( notification )” API sufficient for this need? It cancels any active notification timer. Usage of this is described in the tutorial.

I’ll try. But it seems there’s not a printable value for timer = os.date("!*t", os.time() + 60); ,right?

Hi @WilerJr,

Since you’re dealing with time, have you read the following tutorial? It should be useful to your scenario:

http://www.coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/

Wow! I haven’t read that yet! I’ll take a deep look inside that. I’m almost sure that will help a lot.

Thank you, Brent.

Does system.scheduleNotification work on simulator, Brent? If yes, it’s not working here.

I tried the system notifications API, but I got no success…

Please!

Hi @WilerJr,

I’m not sure I understand the intention here. You want to “force close” the app using a timer or a local notification? As described in the “os.exit()” API documentation:

 

“It is highly recommended that you do not call this function in a release version of your application. Calling os.exit() terminates the application process immediately, which can be interpretted by an app reviewer as a crash, causing your application to be rejected.”

 

So, I don’t recommend you use “os.exit” at all. This seems like it would be strange behavior from a user standpoint… like a ticking time bomb before the app terminates? Maybe I’m not understanding the overall goal here.

 

In regards to Local Notifications, did you reference this tutorial?

http://www.coronalabs.com/blog/2012/06/05/local-notifications-guide-ios/

 

Sincerely,

Brent Sorrentino

Brent?

Hi @WilerJr,

Oops, I almost forgot to respond to this. You’ll need to test “system.scheduleNotification” on a device, not the Simulator.

Take care,

Brent

Hi, Brent, and thanks for the answer.

My overall goal is the following: I want the player to choose a certain number of minutes to define in how much time he wants the game to exit, get it?

The player is going to decide that, so I think he won’t think that’s a crash.