Mobile Local Notification

Moderators: LCNeil, heatherlaine, kevinmiller, elanorb

Post Reply
marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Mobile Local Notification

Post by marcelloe » Wed Feb 05, 2014 6:52 pm

I have looked over the lesson on using Local Notification and I understand how to use it for the most part. In the example they have created field for the message, view and so on. What I don't understand is do I have to create those field for it work or can I create them with in the statement? Do I have to use the local variables?

mobileCreateLocalNotification tAlertBody, tAlertButton, tAlertMessage, tNotificationTime, tSound

I want to create an alarm to go off at a certain time the user requests, or is this not right way to accomplish this?

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Mobile Local Notification

Post by LCNeil » Fri Feb 07, 2014 5:28 pm

Hi Mark,

The local notification lesson http://lessons.runrev.com/s/lessons/m/4 ... ifications)is just an example of how to setup a notification and you you can change it to operate in any way you want. You don't need to use fields and the data can be hard scripted if needed.

You should be able to edit the lesson to suit your needs by including the time (see "time" function")instead of a specified interval. The sound would have to be part of the application as the "playSound" parameter of local notifications relates to the notification tone of a device

Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
--

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Mobile Local Notification

Post by marcelloe » Fri Feb 07, 2014 7:16 pm

This is a 2 part question. Can the Mobile Local Notification be used on a field? The field will have a time for notification to go off, but the time might come from another field on another card. How do I use the time from field in question. I hope that is not confusing.

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Mobile Local Notification

Post by LCNeil » Mon Feb 10, 2014 2:57 pm

Hi Mark,

Local notifications are setup between the applications and the operating system and cannot be directly applied to a field. A local notification is what you see when you are generally outside of the application and you want to inform your user to return to your application (e.g. Candy Crush- All life's replenished, Diet App- Inform user that it is time to eat).

These notification occur via an alert that displays a notification within the devices notification centre.

From what you have suggested, it sounds like you want to have a field display a notification at a specified time (e.g. via time in another field). If this is the case, then you should be able to create this yourself in LiveCode. I would recommend looking up the date and time functions that are available in LiveCode as this will allow you to put the current date/time in a field.

Then you could implement a non-blocking check (send http://livecode.com/developers/api/6.0.2/command/send/) that check a supplied time against the current time. If these match, then you can display a notification (e.g. answer dialog)

Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
--

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Mobile Local Notification

Post by marcelloe » Wed Feb 19, 2014 4:06 pm

I am not sure how to set the time for the alert. I have the user select a day and I want the alert to go off on that day. I am using tDateResult to put the date into the corresponding field. Can I use tDateResult in the mobileCreateLocalNotification alertTime selection? Can I set the alert to go off at a specific time on the day selected.

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Mobile Local Notification

Post by LCNeil » Thu Feb 20, 2014 12:00 pm

Hi Mark,

A time for an alert is given in seconds. This seconds, in LiveCode, is the amount of time from the beginning of the Unix EPOCH (time elapsed since 00:00:00 Thursday, 1 January 1970). So in order to calculate a time to trigger an alert, you have to convert a given date to seconds.

The following is a simple script that will do this conversion from a mobilePickDate-

Code: Select all

on mouseUp
   mobilePickdate "date"
   put the result into tDateResult
   convert tDateResult to seconds
   answer tDateResult
end mouseUp
Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
-

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Mobile Local Notification

Post by marcelloe » Thu Feb 20, 2014 3:55 pm

To complicate things I also want the date they selected to be put into a field. Converting the date to seconds will that mess up that input?

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Mobile Local Notification

Post by LCNeil » Thu Feb 20, 2014 4:10 pm

Hi Mark,

Easiest thing to do would be to put the date in a field before any conversions take place.

Code: Select all

on mouseUp
   mobilePickdate "date"
   put the result into tDateResult
put tDateResult into field "date"
   convert tDateResult to seconds
   answer tDateResult
end mouseUp
Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
-

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Mobile Local Notification

Post by marcelloe » Thu Feb 20, 2014 4:34 pm

I want to the alert to go off at 7AM on the day the user selected? Also, I assume I put tDateResult in the selection alertTime?

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Mobile Local Notification

Post by LCNeil » Thu Feb 20, 2014 4:59 pm

Hi Mark,

There are 3600 in an hour and I believe that selecting a date e.g. 21/02/14, would result in a notification triggering at midnight. If you want it to go off at 7AM then you have to add the appropriate amount of seconds on to this value (3600 x 7 = 25200)

Yes, the converted tDateResult is what you would use for the alertTime parameter is what you need to set with the value of tDateResult in my script.

Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
-

Post Reply

Return to “idea2app and Coding School”