firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
819 stars 424 forks source link

[Bug] "FirebaseMessaging.RequestPermissionAsync()" is incorrect. #1352

Closed fanhonglin-t4f closed 10 months ago

fanhonglin-t4f commented 10 months ago

[READ] For Firebase Unity SDK issues, please report to Firebase Unity open-source

Once you've read this section and determined that your issue is appropriate for this repository, please delete this section.

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

I'm trying to run messaging/testapp. The logic of the code(FirebaseMessaging.RequestPermissionAsync()) is inconsistent with the comments. The comment says "This will display the prompt to request permission" image But actually the prompt is not displayed at all

It happened on Android12, Android13, OPPO Rendo 9, Pixel 4. (Android12 will pop up a prompt during the application startup phase, while Android13 will not pop up a prompt.)


So, is the comment of the method RequestPermissionAsync simply wrong? Should I manually implement the request permission prompt myself?

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? Yes What's the issue repro rate? (eg 100%, 1/5 etc) 100%

What happened? How can we make the problem occur? No prompt shown. Normal start. This could be a description, log/console output, etc.

If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue. Just use quickstart-unity

Relevant Code:

Firebase.Sample.Messaging.UIHandler.InitializeFirebase

            // This will display the prompt to request permission to receive
            // notifications if the prompt has not already been displayed before. (If
            // the user already responded to the prompt, thier decision is cached by
            // the OS and can be changed in the OS settings).
            FirebaseMessaging.RequestPermissionAsync().ContinueWithOnMainThread(
                task => { LogTaskCompletion(task, "RequestPermissionAsync"); }
            );
a-maurice commented 10 months ago

So the issue is that RequestPermissionAsync is only meant to pull up the prompt on iOS. On Android (and desktop) it will immediately return as a success. I'll update the comment to make it clearer.