Firebase notifications "tied" to one App

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Firebase notifications "tied" to one App

Post by simon.schvartzman » Fri Feb 26, 2021 3:51 pm

Eddie see answers below
Previously you said you didn’t not use Google APIs so I went straight to Firebase to create a project. But in the screenshots that you posted I saw that you had created a project in Google API AND Firebase
As I said I worked on this project 2+ years ago and I don't remember what exactly I did then. I'm a senior person and my memory is not the same as it used to be, among other things that are not the same as they used to be :(
Do I need to link both of them together if so how should I go about doing it?
I guess both are linked by the Project Name
Also, yours is 100% working now and there’s nothing that is bothering you?
Yes, last time I checked everything was 100% working. And yes, there are many things bothering me: my wife, my kids, my bank and mainly not having a COVID vacine available but I guess this is not what you want to know :D :)

Keep trying !!!
Simon
________________________________________
To ";" or not to ";" that is the question

EddieLee
Posts: 118
Joined: Thu Oct 25, 2018 1:06 pm

Re: Firebase notifications "tied" to one App

Post by EddieLee » Fri Feb 26, 2021 5:25 pm

simon.schvartzman wrote:
Fri Feb 26, 2021 3:51 pm

I guess both are linked by the Project Name
Hi Simon, thanks for your help. But do you remember how you link both together? Do you remember doing migration or anything? Because it doesn’t make sense if both Google API and firebase is linked just by having the same name. I’m assuming your firebase is the main engine running and your Google API is redundant. Let me try it out tomorrow using your way. Btw I tried using firebase but idk why my senderID is only 11 digits instead of 12 and also my APIkey has that special semi colon thing. I’m going crazy over it now.

Thanks so much for your help again!
Eddie
Eddie :D

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Firebase notifications "tied" to one App

Post by simon.schvartzman » Fri Feb 26, 2021 6:15 pm

I guess the sequence goes like this:

1 - create a new project in Google API
Screen Shot 2021-02-26 at 14.11.25.png
2 - Add a new project in Firebase

Screen Shot 2021-02-26 at 14.11.47.png
3 - Select the project you have just created in Google API
Screen Shot 2021-02-26 at 14.12.00.png
Simon
________________________________________
To ";" or not to ";" that is the question

EddieLee
Posts: 118
Joined: Thu Oct 25, 2018 1:06 pm

Re: Firebase notifications "tied" to one App

Post by EddieLee » Sat Feb 27, 2021 11:25 am

Hi Simon,

I've followed the steps that you have provided, and i have received a success message. However on my physical device, i did not get any notifications at all. Let me share some of the screen that i think might be useful in finding out where's the issue. I really dont know what could went wrong, i used the file on https://lessons.livecode.com/m/4069/l/5 ... th-android to try to send the notifications to my physical device. Maybe there is something wrong with the file ? What is payload used for when sending notifications?


standalone setting.jpg
test notification.jpg
stack.jpg
Here is the code used to send notifications to my device
Card script

Code: Select all

command pushNotificationAndroid pAPIKey, pDevices, pTitle, pBody, pBadge, pSound, pPayload
   local tDataA, tNotificationA, tNotification, tHeaders
   
   # build data element of notification
   put pTitle into tDataA["title"]
   put pBody into tDataA["body"]
   put pBadge into tDataA["badge_value"]
   put pSound = true into tDataA["play_sound"]
   put pPayload into tDataA["payload"]
   
   # build notification
   put tDataA into tNotificationA["data"]
   split pDevices with LF
   put pDevices into tNotificationA["registration_ids"]
   put "Splash21" into tNotificationA["collapse_key"]
   
   # create a JSON encoded message
   jsonEncode tNotificationA, tNotification
   
   # headers
   put "Content-Type: application/json" & LF into tHeaders
   put "Authorization: key=" & pAPIKey & LF after tHeaders
   set the HTTPHeaders to tHeaders
   
   # had a couple of errors that were resolved by setting/resetting this flag  :/
   libUrlSetSSLVerification false
   
   # send the notification
   # URL updated on 19 Feb 2018
   post tNotification to url "https://fcm.googleapis.com/fcm/send"
   return it
  
   
end pushNotificationAndroid
Button Script

Code: Select all

on mouseUp
   put empty into field "Result"
   pushNotificationAndroid field "APIKey", field "Devices", field "Title", field "Body", the label of button "Badge", the label of button "Sound", Field "Payload"
   put the result into field "Result"
end mouseUp
Result return was
{"multicast_id":674397827141276168,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1614424620452672%f32a374f90939706"}]}

P.S. I have also checked that my device number is the same and am wondering do i need to add another command for pushnotificationreceived? Because i think im very close to being successful now.
Thanks!
Eddie
Eddie :D

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Firebase notifications "tied" to one App

Post by simon.schvartzman » Sun Feb 28, 2021 6:27 pm

Hi Eddie, I'm glad you are making progress...
...am wondering do i need to add another command for pushnotificationreceived?
Not sure why you say "another" command but answer is yes, in your physical device you do neeed a Command to handle the received notification, to start with it can be a very simple one like this:

Code: Select all

on pushNotificationReceived tMessage
    answer tMessage
end pushNotificationReceived
What is payload used for when sending notifications?
Payload is the actual contents of the notification

Question: do you see an icon on the status bar of your physical device (the very top raw of the sceen) indicating a notification was received? If you don't see it then for some reason the notification has not reached the device
icon.jpg
Simon
________________________________________
To ";" or not to ";" that is the question

EddieLee
Posts: 118
Joined: Thu Oct 25, 2018 1:06 pm

Re: Firebase notifications "tied" to one App

Post by EddieLee » Mon Mar 01, 2021 12:09 am

Hi Simon,
Not sure why you say "another" command but answer is yes, in your physical device you do neeed a Command to handle the received notification, to start with it can be a very simple one like this:
Reason for asking because I remember not using it previously when I did notifications. However when I added your codes to handle the received notification, suddenly it worked. But due to me not needing to show any message in the app when the user receive a notification I left the command on pushnotificationreceived blank and still was able to receive it.
Payload is the actual contents of the notification
What does it mean the “actual contents” of the notifications? I tried leaving it blank and typing a bunch of random things and still was able to receive the notification successfully.
Question: do you see an icon on the status bar of your physical device (the very top raw of the sceen) indicating a notification was received? If you don't see it then for some reason the notification has not reached the device
Yes Simon, I finally am able to receive the notification after adding in the command on pushnotificationsreceived before that I was unable to receive anything or was able to receive but there was no output from the app or a way to let the app display that there are notifications.

Question:
1. Have you tried sending notifications to multiple devices within a single script or a single post to the FCM URL? Or is it only possible by sending multiple post request to the FCM URL?

2. Can I use the same way that we have done here to send push notifications to IOS or if not what would be a good/suitable way?

Thanks so much for your help and hope that we can continue to do it!
Eddie :D

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Firebase notifications "tied" to one App

Post by simon.schvartzman » Mon Mar 01, 2021 2:12 pm

What does it mean the “actual contents” of the notifications? I tried leaving it blank and typing a bunch of random things and still was able to receive the notification successfully.
A notification has 3 parts:
1 - A Title
2 - A Body, which I'd prefer to call an Alert
3 - A Payload which I'd prefer to call its content

Just to (hopefuly) clarify: when you receive the notification in the home screen you will see just the Title and the Body. The actual content (Payload) will only be shown when the notification is read/displayed

There are some particularities as how iOS and Android deal with the notifications depending if the App is open or closed at the moment the notification arrives. You should do some testing to find out the differences because I don't recall them all
1. Have you tried sending notifications to multiple devices within a single script or a single post to the FCM URL? Or is it only possible by sending multiple post request to the FCM URL?
Since each device has its unique TokenID there is no way (AFAK) to send the same notification with a single post. The script could be the same but you have to address each device by its own TokenID
2. Can I use the same way that we have done here to send push notifications to IOS or if not what would be a good/suitable way?
Yes and No.

Yes: The principle is the same in the sense that you need to get the TokenID for the device but you will also need to know if the device is running iOS or Android because there are different routines to send notifications to each device. I guess FB can be used for both platforms but I don't know how to do it and besides I understand there is some integration to be done on the iOS device and I doubt this could be done in Livecode.
No: Setting up PushNotifications in iOS is a completly different animal. There is a Lesson on that you should follow.
https://lessons.livecode.com/m/4069/l/5 ... s-with-ios
FYI I had to buy Livecode support in order to get it working for the first time...and before you ask I'm not sure I remember how to do it now
Simon
________________________________________
To ";" or not to ";" that is the question

EddieLee
Posts: 118
Joined: Thu Oct 25, 2018 1:06 pm

Re: Firebase notifications "tied" to one App

Post by EddieLee » Mon Mar 01, 2021 4:27 pm

Hi Simon,

For the payload, will there be any difference if I use different texts or leaving it empty? Because I don’t really understand what’s the use of it and cannot see the difference between the notifications it sent. So what should a standard payload be? How do I know I’m setting a wrong payload?

For sending notifications to multiple devices, I’m guessing I’ll probably have to use a repeat code for each tokenID and post it 1 by 1 to the URL?

So notifications for IOS is an even harder thing than doing for android? No wonder iOS developers earn so much money. :shock:

Thanks so much for your help!
Eddie :D

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Firebase notifications "tied" to one App

Post by simon.schvartzman » Mon Mar 01, 2021 4:55 pm

For the payload, will there be any difference if I use different texts or leaving it empty?
don't know but my guess is that it will be OK to leave it empy

Because I don’t really understand what’s the use of it and cannot see the difference between the notifications it sent. So what should a standard payload be? How do I know I’m setting a wrong payload?
Example (with that I run out of imagination on how to explain to you what the Payload is :) )
Title: MyAppName
Body: Has sent you a notification
Payload: Hi Eddie, how are you? This is the Payload of the notification

I guess there is no "wrong" payload
For sending notifications to multiple devices, I’m guessing I’ll probably have to use a repeat code for each tokenID and post it 1 by 1 to the URL?
Correct
So notifications for IOS is an even harder thing than doing for android?
Yes, at least for me it was
No wonder iOS developers earn so much money
Not sure about this

You are welcome, good luck
Simon
________________________________________
To ";" or not to ";" that is the question

EddieLee
Posts: 118
Joined: Thu Oct 25, 2018 1:06 pm

Re: Firebase notifications "tied" to one App

Post by EddieLee » Tue Mar 02, 2021 12:13 am

Hi Simon,

Usually, the content of the payload I would put it in the body instead as it makes more sense. Thanks for the help anyways, I guess it’s time to start to try doing push notifications for IOS now.

Wish me luck!
Eddie :D

Post Reply

Return to “Android Deployment”