godot-local-notification icon indicating copy to clipboard operation
godot-local-notification copied to clipboard

Questions about notifications

Open tigz19 opened this issue 3 years ago • 24 comments

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?

tigz19 avatar Jan 26 '21 16:01 tigz19

@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.

DrMoriarty avatar Jan 26 '21 19:01 DrMoriarty

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.

ViRGiL175 avatar Jan 27 '21 08:01 ViRGiL175

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!

TIBI4 avatar Jan 27 '21 14:01 TIBI4

@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.

DrMoriarty avatar Jan 28 '21 12:01 DrMoriarty

@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?

martinpelli avatar Mar 07 '21 22:03 martinpelli

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

slabgames avatar Mar 13 '21 09:03 slabgames

I just released https://github.com/DrMoriarty/godot-firebase-cloudmessaging try it

DrMoriarty avatar Mar 14 '21 17:03 DrMoriarty

@DrMoriarty That´s only on Android?

martinpelli avatar Mar 14 '21 19:03 martinpelli

@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 avatar Mar 14 '21 19:03 martinpelli

@DrMoriarty on Android: image

martinpelli avatar Mar 14 '21 19:03 martinpelli

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

DrMoriarty avatar Mar 15 '21 07:03 DrMoriarty

@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.

DrMoriarty avatar Mar 15 '21 07:03 DrMoriarty

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

slabgames avatar Mar 15 '21 09:03 slabgames

@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 avatar Mar 15 '21 17:03 martinpelli

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')

martinpelli avatar Mar 15 '21 17:03 martinpelli

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.

DrMoriarty avatar Mar 15 '21 17:03 DrMoriarty

@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

martinpelli avatar Mar 15 '21 18:03 martinpelli

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

DrMoriarty avatar Mar 15 '21 18:03 DrMoriarty

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

DrMoriarty avatar Mar 15 '21 18:03 DrMoriarty

@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 avatar Mar 15 '21 18:03 martinpelli

@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 avatar Mar 15 '21 23:03 martinpelli

@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!

martinpelli avatar Mar 15 '21 23:03 martinpelli

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.

DrMoriarty avatar Mar 16 '21 05:03 DrMoriarty

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).

fbcosentino avatar Sep 07 '21 14:09 fbcosentino