DrMoriarty / godot-local-notification

Godot module for local notifications (android and iOS)
MIT License
139 stars 24 forks source link

Questions about notifications #9

Open tigurik opened 3 years ago

tigurik commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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

martinpelli commented 3 years ago

@DrMoriarty That´s only on Android?

martinpelli commented 3 years ago

@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 commented 3 years ago

@DrMoriarty on Android: image

DrMoriarty commented 3 years ago

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

DrMoriarty commented 3 years ago

@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 commented 3 years ago

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

martinpelli commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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

DrMoriarty commented 3 years ago

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

martinpelli commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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