Push notifications

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Push notifications

Post by Opaquer » Wed Aug 21, 2013 7:08 am

Hey everyone

I'm feeling bad for making so many posts, but there's so much new things with Livecode I'm still getting used to it all :P. Anyway, I had a question about push notifications. Ideally, what I want to happen is we'll have people download the app, and a day or two before the event, they'll get a push notification saying that there's an event tomorrow.

I've got the push notification side of it working. I can make my phone have a push notification when I enter it into a stack from computer, as per the tutorial using pushNotificationAndroid. But, to do that, I had to get the device token and email it to myself, then put that ID into the push notification app. Now, my question is this: how can I automatically get the device ID from someone's phone and have it sent to me somehow? Or is there perhaps a better way to do it?

The alternative I was looking to was mobileCreateLocalNotification. Then, there could perhaps be a text file on dropbox that the app would read every day at 5pm for example, and send out whatever the text file says. The issue with that is if the device isn't connected to the internet at 5pm, they might miss the notification.

Ideally I'd like to use pushNotificationAndroid, since it's really easy and doesn't need to update itself at 5pm every day to check for notifications. But I don't want the user having to send me an email of their device ID, since I want to keep it simple :P!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Push notifications

Post by Simon » Wed Aug 21, 2013 7:35 am

Would mobileCreateLocalNotification work for you?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Push notifications

Post by Opaquer » Wed Aug 21, 2013 7:38 am

It would, but how would I be able to make it work for everyone at once? I've looked into it, and it looks good! The only issue I have is how I would make it get notifications. One way I was thinking was having a text file be read through dropbox, and once a day check the file and create a notification based on that. Though, with that, if the user isn't connected to the internet, would it still work, or would it make an error/just not make any notification?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Push notifications

Post by Simon » Wed Aug 21, 2013 7:47 am

Well...
You know when the event is happening in advance, so you would just set alertTime to a date in the future.
Now what I'd like to know is if an app can cancel an alert after it's been set. (suppose one made an error or the event was canceled)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Push notifications

Post by Opaquer » Wed Aug 21, 2013 7:51 am

Hmm. That is true, but how would it do it every time there's a new function?

Also, with the first method - I can make the phone get the device ID quite easily, but it's the getting it to me that's an issue. Is there a way to save a dropbox file or something similar. So, I could have something like this:

on pushNotificationRegistered tMessage
update dropboxfile "filename" with tmessage
end pushNotificationRegistered

Just as an example. Because then I would have a list of device ID's, which would be perfect!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Push notifications

Post by Simon » Wed Aug 21, 2013 7:59 am

I'm rejecting the method in which the user has to register. But maybe because it's a youth group they might have a newsletter or something that says it's OK.
That is true, but how would it do it every time there's a new function?
Using the dropbox and text file idea new notifications could be added, old ones dropped off the text file.

On to your 'other' post with the field problem... I haven't got a clear answer but you read an .lc file... why?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Push notifications

Post by Opaquer » Wed Aug 21, 2013 8:09 am

We do indeed have a newsletter! How would that help with the other method though?

Also, with the dropbox file and the local notification, this was my idea: When the app is opened and the list of events is loaded up, it gets the first line of the text file, which will be a date and time. I'll then somehow work out the number of seconds from now until the time of the event and make a local notification for 12/24 hours before that event.

The issue with it is what will happen if they open the app more than once? Will they end up getting more than one notification for the same event?

Also, for my other topic - I'm not sure. I used the .lc file for the state issue I had, and figured it would still work. It works on computer when I test it, but not on my phone. Is it really as simple as the file extension :S? If so, what do you recommend I change it to?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Push notifications

Post by Simon » Wed Aug 21, 2013 8:24 am

The issue with it is what will happen if they open the app more than once? Will they end up getting more than one notification for the same event?
I think you would store the info in the .lc file, if it's not there add if it is there ignore.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Push notifications

Post by Opaquer » Wed Aug 21, 2013 8:39 am

Hmm. This is just very brief work, but something like this:

{load dropbox file to notificationevent}
if file "notification.lc" does not exist then
{make file "notification.lc" in path notificationpath}
put line 1 of notificationevent to eventtime -- time and date of event
put timeofevent-currenttime into secondsleft -- not sure about this part yet :(
put secondsleft into line 1 of "notification.lc"
put line 2 of notificationevent to eventname -- name of event
put eventname into line 2 of "notification.lc"
{make local notification}
else
if line 1 of "notification.lc" is not line 1 of notificationevent then
{make new notification}
{make local notification}
else
do nothing
end if
end if

obviously this is very rushed and might not work, but something along those lines?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Push notifications

Post by Simon » Wed Aug 21, 2013 8:45 am

Maybe... :)
But now you have to tell me the name of your group :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Push notifications

Post by Opaquer » Wed Aug 21, 2013 8:55 am

I'll have to give it a try when I get back! And the name of what group? The youth group I'm with?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Push notifications

Post by Simon » Wed Aug 21, 2013 9:02 am

Yep.
Want to know if I'm helping the "Evil Empire" or the "Rebel Alliance" :)
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Push notifications

Post by Opaquer » Wed Aug 21, 2013 9:09 am

Ha! I'm not that evil :P! It's called Betar. I'm in Australia, so it's Betar Australia. It's a Jewish youth movement run by young adults (18-22ish) for younger kids. We run camps, functions etc throughout the year. Since I'm the head of technology this year, I decided we should get a phone app. So here I am :P

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Push notifications

Post by Simon » Wed Aug 21, 2013 9:17 am

Well I'm glad you found LC.
It's great for the app you want.

I still haven't found any link to adding an event to the local calender, you may have to rethink this.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Push notifications

Post by Opaquer » Wed Aug 21, 2013 12:49 pm

As am I :D!

And me either :(. I'm thinking we might just have to not have a calender, and just have a list of functions :(. It won't look at nice, but at least it's something.

Ah well, now to do lost and lots and lots of testing to try and get the push notification code working :P. Any idea how to figure out how long between two points in time :P?

Post Reply