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

Firebase notifications "tied" to one App

Post by simon.schvartzman » Tue Jul 09, 2019 2:34 pm

Hi all, help needed with the following:
In order to learn about Push Notifications I successfully followed the lesson on the subject (http://lessons.livecode.com/m/4069/l/5 ... h-android) and was able to register to Firebase with the basic App.

Once everything was working, meaning I was able to send Notifications using the stack included in the lesson, and my basic App was able to read them time has come to add notifications to my main App.

I did the following:
  • Copied all the settings form the basic App to the main App including the Push Sender ID number
  • Deleted the basic App from the Device
to my surprise the main App never gets registered.

It is like the device and or the basic App are "locked/tied" to the Firebase service.

I have tried with other device, where the basic App was never installed, and still the main App doesn't register.
I have even tried to create a new Google Cloud Project + Firebase Message and nothing has changed, the basic App is the only one getting registered.

Questions:
- is anything I'm missing?
- is there any way to "un-register" a device or App?

Any other suggestions?

Many thanks in advance for any help, I have been scratching my head for two days now...
Simon
________________________________________
To ";" or not to ";" that is the question

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Firebase notifications "tied" to one App

Post by sphere » Wed Jul 10, 2019 2:00 pm

Have to check with the console when have time tonight.
But as far as i know the push ID is connected to the project you have in Firebase console.
Remove any other app from your device with the same id (should not matter)
You could check for the register token with an answer command

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 » Wed Jul 10, 2019 2:16 pm

Thanks sphere
Have to check with the console when have time tonight.
Looking forward for your findings...
But as far as i know the push ID is connected to the project you have in Firebase console.
This is also how I see it as Firebase only allows to select from projects that were created in the Google Cloud Console
Remove any other app from your device with the same id (should not matter)
I did so, I even installed the main App on a device where the basic App was never installed and still no registering...
You could check for the register token with an answer command
Don't know how to do it, can you guide me?
Simon
________________________________________
To ";" or not to ";" that is the question

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 » Wed Jul 10, 2019 5:00 pm

Found the problem, now I need help to find the solution!

With the code below, the device gets registered only if the line answer "Holy Cow!!!" is commented

Code: Select all

on pushNotificationRegistered pMessage
   answer "Registered:" && quote & pMessage & quote with "Okay"
   // Update the e-mail address as required
   --revMail "yourmail@yourmail.com",,"token",pMessage
end pushNotificationRegistered

on pushNotificationReceived tMessage
   answer "Notificação:" && quote & tMessage & quote with "OK"
end pushNotificationReceived

on OpenStack
   --answer "Holy cow!!!"
end OpenStack
What am I missing?

p.s.: same behaviour on Android & iOS so I'm pretty sure the buggy platform is "myself"
Simon
________________________________________
To ";" or not to ";" that is the question

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Firebase notifications "tied" to one App

Post by sphere » Wed Jul 10, 2019 9:40 pm

Hi,

on one app which works OK with FCM i have the pushregister stuff in a hidden button"pnt" on the first card which i use as a splash.
But this can also be just in your Stack script(there was a bug one time where the pushregister did not work when called after another command, but it was solved with a newer LC version).

Code: Select all

on pushNotificationRegistered tSignature
   if tSignature is not empty then
      #answer "Registered for Push Notification:" && quote & tSignature & quote #disable when ok
      put tSignature into URL ( "file:" & specialFolderPath("Documents")  & "/regid.txt" )
      put "yes" into URL ( "file:" & specialFolderPath("Documents")  & "/fcmreceiveyesno.txt" )
   end if
   --answer tSignature
end pushNotificationRegistered

--on pushNotificationRegistrationError tMessage
--answer "Failed to Register for Push Notification:" && quote & tMessage & quote with "Okay"
--end pushNotificationRegistrationError
Then in the stack script i have this because it checks if the token is there and i made an option where the user can turn this push notification on or off, so it sends the key and a yes or no from the created txt files to my DB. (i believe this insert in front piece came from Richard Gaskin time ago)

Code: Select all

put specialFolderPath("Documents") & "/regid.txt" into tRegidFile
   if there is not a file tRegidFile then
      insert the script of button "pnt" into front
      wait 1 second with messages
   end if
   
Of course you can do it another way, but your script is OK.

Only the keys and a yes in my db will receive the push notification.
So i also created a windows app from where i will send the push notification to the keys with yes and it will count the nr of devices where it is send to(via the string received from FCM)
This returned fcm string also gives info about uninstalled devices or succes or canonical (keys of devices where the app is uninstalled should be removed)

I checked in the console: on your project there is the push send id 12 numbers and the app identifier, both have to match.
Then make sure that the image you use for the notification is only white on a transparent background(previous colors where allowed, not anymore), if you use a color image it won't work

So in your script you seem to miss nothing, but maybe in the standalone setting things may not match with your FCM project.
And you need your own key of course to send the push notification to your app.

Hope this helps a bit

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 » Wed Jul 10, 2019 11:11 pm

Thanks again sphere:
...on one app which works OK with FCM i have the pushregister stuff in a hidden button"pnt" on the first card which i use as a splash...
I guess this is it, that will somehow explain why it works if I have nothing inside on openStack
This returned fcm string...
I'm assuming you are using some other FCM APIs to get this string, right? I haven't gone so far yet...
Then make sure that the image you use...


Again I'm at the very beginning with FCM & Notifications, I didn't even know that images can be added to Notifications

I guess your windows App could be a great inclusion to the LC lessons on Notifications if you are open to share it...

Thanks and regards...
Simon
________________________________________
To ";" or not to ";" that is the question

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 » Thu Jul 11, 2019 1:12 am

Hi sphere, no joy yet...

I'm confused as where exactly do you add this code:

Code: Select all

     insert the script of button "pnt" into front
      wait 1 second with messages
 
I have tried 4 options:

1 - on the main preOpenStack
2 - on the main openStack
3 - on openStack of the card where button "pnt" is located
4 - on openCard of the card where button "pnt" is located

and none of them worked
Simon
________________________________________
To ";" or not to ";" that is the question

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Firebase notifications "tied" to one App

Post by sphere » Thu Jul 11, 2019 9:19 am

Hi Simon,

i have that piece of code in the OpenStack handler. But it should not really matter if it is in preOpenstack or Openstack.

But the pushNotificationRegistered should be called automatically if it is in your stackscript.

When there is no txt file with the token in it it will be call as first thing to do.

Do you use the script as i used? Because if the txt file exists then it won't call the onpushregisterd handler.

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 » Thu Jul 11, 2019 1:31 pm

Hi sphere, many thanks for your patience and your willingness to help.

At this point I'm not taking into account the "txt" file as I'm not actually being able to send any notification until I get the device to register.

So I'm only using the two lines to insert the script as the very first two lines of the stackscript

Code: Select all

on preopenStack
	insert the script of button "pnt" into front
	wait 1 second with messages
end preopenStack
and the script of button "pnt" is

Code: Select all

on pushNotificationRegistered pMessage
   answer "Registered:" && quote & pMessage & quote with "Okay"
   // Update the e-mail address as required
   --revMail "youremail@youremail.com",,"token",pMessage
end pushNotificationRegistered
The strange thing is that it works OK with the very simple stack that does nothing but to register, but when I insert the same code into my main project it does not work...

Is driving me crazy...
Simon
________________________________________
To ";" or not to ";" that is the question

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 » Thu Jul 11, 2019 4:01 pm

Hi sphere I found the original bug report (https://quality.livecode.com/show_bug.cgi?id=21259) on the subject and decided to ask to reopen it because in my view LC 9.0.4 is definitely not behaving as it should.

Once again, as I see it, a simple stack as the one below should be able to register without any further complications but is not the case unless openStack is empty (or someone proves me wrong).

Code: Select all

on pushNotificationRegistered pMessage
   answer "Registered:" && quote & pMessage & quote with "Okay"
   // Update the e-mail address as required
   --revMail "yourmail@yourmail.com",,"token",pMessage
end pushNotificationRegistered

on pushNotificationReceived tMessage
   answer "Notificação:" && quote & tMessage & quote with "OK"
end pushNotificationReceived

on openStack
   answer "Holy cow!!!"
end openStack
Simon
________________________________________
To ";" or not to ";" that is the question

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Firebase notifications "tied" to one App

Post by sphere » Thu Jul 11, 2019 5:41 pm

Hi Simon,

i've seen your addition to the bug report.
What if:
--you first save the token to a variable or a txt file and revemail it with another handler?
--You test with lc901rc2 or lc905?

on another stack i have this onpushregistration just in the Stack script and save it also to txt file.

Code: Select all

on pushNotificationRegistered tSignature
   if tSignature is not empty then
      --answer "Registered for Push Notification:" && quote & tSignature & quote #disable when ok
      put tSignature into URL ( "file:" & specialFolderPath("documents")  & "/regid.txt" )
   end if
   --answer tSignature
end pushNotificationRegistered

on pushNotificationRegistrationError tMessage
   if the environment is "mobile" then
   answer "Zorg aub eerst voor Internet verbinding en start de App opnieuw" --make sure you have internet access--we need the token
   go to card"splash"
   closeStack
   end if
end pushNotificationRegistrationError
With this stack the token is only send when the customer orders something, so when the seller starts handling the order then Pushnotfications are send to the customers phone.
As far as i can see this still works.
and here i also check the same but then in preOpenstack:

Code: Select all

if there is not a file tRegidFile then
         --answer"no fcm file"
         ------insert the script of button "pnt" into front --you see i don't use this now as it is commented out
         pushNotificationRegistered --in lc901rc2 werkt ok
         wait 1 second with messages
      else
         if there is a file tRegidFile then
            --answer"fcm file is there"
            put url("file:" & tRegidFile) into gFcmReg
            --answer gFcmReg
         end if
      end if
Hopefully you will succeed.

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 » Thu Jul 11, 2019 10:38 pm

Hi sphere, remarks below
What if:
--you first save the token to a variable or a txt file and revemail it with another handler?
I'm afraid I'm not making myself clear (english is not my mother tongue)...
The problem is neither where to save the token nor how to handle it, the problem is that I can't get the token (because pushNotificationRegistered is never called)
--You test with lc901rc2 or lc905?
I've tested with LC9.0.1rc2, LC 9.0.3 & LC 9.04 (all of them Indy versions...) I'll test with 9.0.5 rc and report the result but I'm not very optimistic...

Unless I'm doing something terribly wrong (which of course has to be taken into consideration) I would guess it is a bug and the workaround you suggested for some reason doesn't work in my case.

Best and many, many thanks for your support

EDIT: LC 9.0.5 rc 1 doesn't make any difference
Simon
________________________________________
To ";" or not to ";" that is the question

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Firebase notifications "tied" to one App

Post by sphere » Fri Jul 12, 2019 7:48 am

Hi Simon,

no problem i understand you, English is also not my native tongue.

What if you explicitly call the handler?

Code: Select all

on openStack
pushNotificationRegistered
end openStack
then also use the answer commend in the pushNotificationRegistered handler.
Is the result of the answer command empty or does it give a token?
At least you should see the answer pop-up

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 Jul 12, 2019 3:13 pm

So @sphere, when running the following stack the answer command returns empty but I would assume this is correct since calling pushNotificationRegistered without the "pMessage" argument should in fact return empty...

Code: Select all

on pushNotificationRegistered pMessage
   answer pMessage
end pushNotificationRegistered

on pushNotificationRegistrationError tMessage
   answer "Failed to Register for Push Notification:" && quote \
         & tMessage & quote with "Okay"
end pushNotificationRegistrationError

on openStack
   pushNotificationRegistered
end openStack
Simon
________________________________________
To ";" or not to ";" that is the question

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Firebase notifications "tied" to one App

Post by sphere » Fri Jul 12, 2019 6:26 pm

Hi Simon,

maybe, but in this case i don't think so becasue the function will put the token in pMessage.
So this was just to see what comes up and force it.

As the dictionary states:
The pushNotificationRegistered message is handled once the application starts up and registers with the Push Notification Server.

The application only tries to register with the Push Notification Server if the application was configured to handle Push Notifications in the pList (iOS) or manifest (Android).

So maybe something goes wrong when creating the manifest when pushing it to the device.
If i remember correct, it should also work with the emulator.

Just to be sure, although i have no doubt, but you have Internet selected right?
androidsetfcm.png
If so, then sorry, i'm out of options.

Regards,
Sphere

Post Reply

Return to “Android Deployment”