Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about notifications #9

Open
tigurik opened this issue Jan 26, 2021 · 24 comments
Open

Questions about notifications #9

tigurik opened this issue Jan 26, 2021 · 24 comments

Comments

@tigurik
Copy link
Contributor

tigurik commented Jan 26, 2021

Hello! Thanks for the hard work, your libraries are very helpful.

I have a couple of questions. Sorry for bad English, I hope you can understand me.

  1. Can I receive push notifications using firebase?
    How can i do this?

  2. Also I see in the README
    get_device_token () -> String
    and register_remote_notification () but they don't work and return nothing am I right?

  3. Can I set a specific time for scheduled notifications? Will this work if the application is closed?

@DrMoriarty
Copy link
Owner

@tigz19 Hello!
For scheduled notifications you should use method show(message: String, title: String, time_delay_in_seconds: int, tag: int). When your app is closed the OS will fire notification in system tray. The user can tap on notification and your app will be opened by it.

For remote (push) notifications the algorithm is dependent on using OS.

For iOS you should do:

  1. check if notifications is_inited, it means that application requested permissions from user.
  2. call init if app didn’t requested it yet.
  3. catch signal enabled or check method is_enabled. It will return false if user didn’t grant you permission.
  4. get device token (get_device_token) for push notifications or catch signal device_token_received
  5. send your device token to the server side.
    That’s all. Sending notifications processed by your server, receiving notifications processed by OS.

For Android of course the best notification solution is Firebase messaging. But I didn’t make new plugin for it yet.
Now I only have old C++ module for Godot 3.1 https://github.com/DrMoriarty/godot-firebase but I’m not sure that it will compile for newest Godot.

@ViRGiL175
Copy link
Contributor

Thanks for your nice libraries, @DrMoriarty

I see the documentation for Android plugins, I know the Android SDK, and it looks good for bundling Android and Godot functionality.

Do you know anything about the status of Godot's iOS plugin support?

As far as I understand, it will be much more convenient to create cross-platform libraries if such plugins are available for all platforms.

@TIBI4
Copy link

TIBI4 commented Jan 27, 2021

I have seen that you made this awesome plugin, DrMoriarty.

But the only thing I don't know how to do is a remote notification, and how will it work on Android. I know there is a register_remote_notification function, but I dont know it's parameters. Can you update the Usage section of the repository and add some example case (Firebase/custom)?

Maybe I haven't seen the documentation, but it doesn't seem to be one though. If there is one, can you share it with us?

Thanks in advance!

@DrMoriarty
Copy link
Owner

@ViRGiL175 I'm sure that in Godot 3.2.4-stable will be new convient iOS plugin support. I'm going to update all my plugins to the new way when stable godot was released.
This new system will add some comfortable control to the plugin user, but it will not solve much plugin developing problems. My plugins code is very OS dependent and very often I should develop two different plugins with the same (or similar) interface to make their usage more simple.

@TIBI4 Yes, remote notifications for Android is not clear now. At first I'm going to make firebase-notifications plugin (because I use it for my projects) and later may be I will make more universal solution for android push notifications.

@martinpelli
Copy link

@DrMoriarty HI, the token that I can get with this module is a token that I can use with Cloud messaging to send a notification to that device? Or the token that use FCM is other token?I mena is a registered token?

@slabgames
Copy link

Do you have firebase-notifications plugin already? @DrMoriarty I tried with the firebase-core and cloud messaging, but it doesn't seem to work

@DrMoriarty
Copy link
Owner

@martinpelli
Copy link

@DrMoriarty That´s only on Android?

@martinpelli
Copy link

martinpelli commented Mar 14, 2021

@DrMoriarty from native it say that is on Android and iOS but it is crashing on iOS, Installing firebase cloud messaging plugin from native and connecting the methods it should be enough? Also the framework in xcode is not there

@martinpelli
Copy link

@DrMoriarty on Android:
image

@DrMoriarty
Copy link
Owner

@martinpelli Put file google-services.json in folder android/build

@DrMoriarty
Copy link
Owner

@martinpelli it is for Android now. iOS version will be ready soon. Now I'm updating all my iOS plugins for support new godot 3.2.4 (with new iOS plugins interface). I hope plugins will be available during the week or so on.

@slabgames
Copy link

@DrMoriarty Thanks so much for this great library, much time saver

@martinpelli
Copy link

martinpelli commented Mar 15, 2021

@DrMoriarty I am getting these errors:

**ERROR**: Condition "err" is true. Returned: err
03-15 14:32:11.843  3691  3771 E godot   :    At: modules/gdscript/gdscript.cpp:829:load_source_code() - Condition "err" is true. Returned: err
03-15 14:32:11.843  3691  3771 E godot   : **ERROR**: Cannot load source code from file 'res://Scripts/messaging.gd'.
03-15 14:32:11.843  3691  3771 E godot   :    At: modules/gdscript/gdscript.cpp:2315:load() - Condition "err != OK" is true. Returned: RES()
03-15 14:32:11.844  3691  3771 E godot   : **ERROR**: Failed loading resource: res://Scripts/messaging.gd. Make sure resources have been imported by opening the project in the editor at least once.
03-15 14:32:11.844  3691  3771 E godot   :    At: core/io/resource_loader.cpp:279:_load() - Condition "found" is true. Returned: RES()
03-15 14:32:11.844  3691  3771 E godot   : **ERROR**: Can't autoload: res://Scripts/messaging.gd
03-15 14:32:11.844  3691  3771 E godot   :    At: main/main.cpp:1766:start() - Condition "res.is_null()" is true. Continuing.
03-15 14:32:18.572  3691  3771 E godot   : **SCRIPT ERROR**: Invalid call. Nonexistent function 'connect' in base 'Nil'.
03-15 14:32:18.573  3691  3771 E godot   :    At: res://Scripts/Reserve_Script2.gdc:57:_ready() - Invalid call. Nonexistent function 'connect' in base 'Nil'.

the weird thing is that on windows I am not getting this errors, the autoload is there on res://Scripts/messaging.gd and the script is there so I don´t understand

@martinpelli
Copy link

martinpelli commented Mar 15, 2021

As I said I am not getting the errors when executing on Windows
Sin títulos
Sin título

Using Messaging.connect('token_received', self, '_on_token_received')

@DrMoriarty
Copy link
Owner

It seems that you have issue with upper case symbols in folder name. Usually plugins install their gd-wrapper to scripts folder (all lower case). In Windows there are no difference in lower/upper case folders, but on mobile phones (both Android and iOS) filesystem differs cases in file and folder names.

@martinpelli
Copy link

@DrMoriarty yeah I tought that but I tested it changing name to scripts and I am having the same problem , so I am gonna try another way, thanks

@DrMoriarty
Copy link
Owner

Try to close Godot and check your project.godot file, section [autoload]. It can be written there in wrong case.

@DrMoriarty
Copy link
Owner

Also you can check your APK file (it just zip archive). You can see your folder names how they are stored inside.

@martinpelli
Copy link

martinpelli commented Mar 15, 2021

@DrMoriarty yes thanks! I am seeing that although I have changed the name of the folder , all the routes are still with the capital S, so I am fixing everything

@martinpelli
Copy link

martinpelli commented Mar 15, 2021

@DrMoriarty so after solving my problem, I can get the token so it´s working!! Thnaks! Now I have two problems:
when sending from firebase console to my device, I can get a message trough the logcat,but there is no notification:

{from:201898469024, messageId:0:1615850189342089%8e6bc0f98e6bc0f9, messageType:Null, notification:{body:NotificationNotificationNotification, title:Notification}, senderId:201898469024, to:Null}

Also I tried sending a notification to a token via http with the token that I get with your plugin , and this url: "https://fcm.googleapis.com/fcm/send"
I can´t get the notification in the device and I am receiving this result body:

{"multicast_id":1245017623099266055,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1615850167221938%8e6bc0f98e6bc0f9"}]}

before without the plugin, I was getting failure:1, so the token is working, but the notification is never shown

@martinpelli
Copy link

martinpelli commented Mar 15, 2021

@DrMoriarty Edit: IT´S WORKING!! The only problem now it´s that the user on the cellphone has to enable floating notifications, the sound of the notification and the notification on phone lockscreen for the app/game. Or maybe this is done automatically when uploading to playstore?
Thanks you are a Master!

@DrMoriarty
Copy link
Owner

Yes, if user don't enable notifications (or disable it) the app will never show any popup.
But we (game developers) have no ways to affect on this. This is the task only between the device user and OS.

@fbcosentino
Copy link

fbcosentino commented Sep 7, 2021

Same issue as martinpelli but I didn't find how to solve it. In my app I have:

func _ready():
	messaging.connect('message_received', self, '_on_message_received')
	
func _on_message_received(message: Dictionary) -> void:
	$Label.text += "Message received: %s\n" % str(message)

When my server sends a message using "https://fcm.googleapis.com/fcm/send", the app shows the JSON in the mobile, so I know all the token part is right and the messaging chain is working. No notifications are shown. Local notifications are shown normally. Did I miss a step somewhere?


Edit: nevermind, got it working. Problem was on server side ("notification" field was missing in the data array).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants