Skip to content

Add set_auto_init_enabled() to Firebase Messaging (Android + iOS) - #45

Open
BlackwindITA wants to merge 1 commit into
godot-x:mainfrom
BlackwindITA:auto-init-toggle
Open

Add set_auto_init_enabled() to Firebase Messaging (Android + iOS)#45
BlackwindITA wants to merge 1 commit into
godot-x:mainfrom
BlackwindITA:auto-init-toggle

Conversation

@BlackwindITA

Copy link
Copy Markdown

The problem

Firebase generates an FCM registration token on first launch. An app that must not collect a device identifier before the user has consented can turn that off declaratively:

  • Android: <meta-data android:name="firebase_messaging_auto_init_enabled" android:value="false" />
  • iOS: FirebaseMessagingAutoInitEnabled = false in Info.plist

But once it is off there is currently no way to turn it back on from GDScript. The plugin exposes initialize, request_permission, get_token, get_apns_token, subscribe_to_topic and unsubscribe_from_topic, and none of them touches auto-init — so the token is never created and push silently never arrives.

This matters beyond convenience: with auto-init left on, Google Play's Data Safety form has to declare the collection as "Required" rather than optional, and a privacy policy cannot name consent as the legal basis.

The change

Adds two methods to Firebase Messaging on both platforms, plus the matching README entries:

  • set_auto_init_enabled(enabled: bool)
  • is_auto_init_enabled() -> bool

Android uses FirebaseMessaging.getInstance().isAutoInitEnabled, iOS uses [FIRMessaging messaging].autoInitEnabled. Both follow the error handling already used by the surrounding methods (Android emits messaging_error, iOS logs).

Usage:

func _on_user_consented() -> void:
    var messaging = Engine.get_singleton("GodotxFirebaseMessaging")
    messaging.set_auto_init_enabled(true)
    messaging.subscribe_to_topic("news")

What I verified, and what I did not

Not verified: I did not build the AAR or the xcframework, so these changes have not been compiled inside this project's build system. They are small and follow the existing patterns, but they deserve a build before merging.

Verified: the underlying platform API is exactly what a shipped app needs. I hit this gap in a Godot 4.7 game that uses this plugin, and worked around it with a ~30-line local GodotPlugin that does nothing but call setAutoInitEnabled. With auto-init disabled in the manifest and that call made only after the player accepts, the chain works end to end on an Android 10 device: FirebaseInitProvider initialization successfulSubscribed to topic → notification delivered with the app closed. This PR is that workaround, moved to where it belongs.

Happy to adjust naming or split the platforms if you prefer.

Firebase generates an FCM registration token on first launch. Apps that
must not collect a device identifier before the user consents can turn
that off in the manifest (Android) or Info.plist (iOS), but there is
currently no way to turn it back on from GDScript -- so the token is
never created and push silently never arrives.

Adds set_auto_init_enabled(bool) and is_auto_init_enabled() to both
platforms, plus the matching README entries.
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

Successfully merging this pull request may close these issues.

1 participant