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

Add support for push notifications #1091

Merged
merged 9 commits into from
Aug 14, 2023
Merged

Add support for push notifications #1091

merged 9 commits into from
Aug 14, 2023

Conversation

klochowicz
Copy link
Contributor

@klochowicz klochowicz commented Aug 11, 2023

Notifications are sent via FCM.
Both background and foreground notifications are supported.

Tested on iOS.

  • foreground
    image

  • background

image

@klochowicz
Copy link
Contributor Author

I closed this PR early due to a GitGuardian warning that we're leaking API keys.

After researching different approaches for a bit (env variables, cloud secret service, firebase shared config) I double-checked that indeed this key is supposed to be public and it's a well known false positive that they just don't care to fix 😖

GitGuardian/APISecurityBestPractices#14

PR is open again, if someone has Android it would be much appreciated to help testing it with me :)

@klochowicz klochowicz self-assigned this Aug 12, 2023
Comment on lines +49 to +64
static const FirebaseOptions android = FirebaseOptions(
apiKey: 'AIzaSyCDI7arcBp4uriwfLySgqrchkNVDVW94uk',
appId: '1:237191932527:android:651be56a933e8bda36bb9a',
messagingSenderId: '237191932527',
projectId: 'project-3195624368411891722',
storageBucket: 'project-3195624368411891722.appspot.com',
);

static const FirebaseOptions ios = FirebaseOptions(
apiKey: 'AIzaSyD1FiZUHkX-rdHUtAXU12ku2e7zmBHqLSQ',
appId: '1:237191932527:ios:ed5586aaa838be1e36bb9a',
messagingSenderId: '237191932527',
projectId: 'project-3195624368411891722',
storageBucket: 'project-3195624368411891722.appspot.com',
iosClientId: '237191932527-70uoogr06k3rrrmslr5u1r6i4st9ch39.apps.googleusercontent.com',
iosBundleId: 'finance.get10101.app',
);
Copy link
Contributor

@bonomat bonomat Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to differentiate between mainnet and regtest?

// Edit // comment should be one line above at the iosBundleId because for regtest it will be different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth differentiating between mainnet and regtest? I would rather assume that the tokens (or registration emails) should filter out our testing from other data, so we have clear data for analytics.

note that the file is autogenerated and should not be tempered with.

Future<void> requestNotificationPermission() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
final token = await messaging.getToken();
FLog.info(text: "Firebase token: $token");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't think this deserves an info log level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guide for Android testers: @bonomat and @Restioson - please DM me your firebase tokens for your Android devices when you deploy, and then I can send you some notifications before the release.

You can do the same from the Firebase Console as well yourselves if you prefer to. I will send a guide today.

mobile/lib/main.dart Outdated Show resolved Hide resolved
mobile/lib/main.dart Outdated Show resolved Hide resolved
Copy link
Contributor

@bonomat bonomat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonably to me. :)
I believe this deserves a changelog entry.

@bonomat
Copy link
Contributor

bonomat commented Aug 14, 2023

PR is open again, if someone has Android it would be much appreciated to help testing it with me :)

I've one, what's the test scenario you want me to tets?

@Restioson
Copy link
Contributor

I've one, what's the test scenario you want me to tets?

I can also test if given instructions :)

Copy link
Contributor

@luckysori luckysori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, no concerns!

Comment on lines +36 to +40
case TargetPlatform.linux:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓So we will throw exceptions every time we send a notification to a test app running on desktop, right? I assume that's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

every time we send a notification to a test app running on linux desktop, macOS is actually supported!

this part was autogenerated by flutterfire :)

if it ever becomes a problem we can detect the platform, and skip subscribing to topics on Linux.

PS have you tried running this code on Linux? if it crashes, I'm happy to pair up to ensure it still works well!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tried it yet, but I will!

Enable the following modes for the needs of FCM:
    - background_fetch,
    - remote_notifications.
Try to start the backend 3 times before giving up.
Makes it clear that one cannot deploy to device and hope that local regtest will
    work (the backend crashes).
Without this, we'd miss the notifications sent via FCM if the user had the app open.

note: The android part has not been tested as I don't have Android.
@klochowicz klochowicz added this pull request to the merge queue Aug 14, 2023
Merged via the queue into main with commit ce583ed Aug 14, 2023
7 checks passed
@klochowicz klochowicz deleted the feat/add-firebase branch August 14, 2023 23:24
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.

Add support for local notifications Add support for Firebase notifications
4 participants