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

[Mobile App] Issue 538: Enable push notifications for iOS #1032

Merged

Conversation

KarinBerg
Copy link
Contributor

@KarinBerg KarinBerg commented Jan 28, 2025

Followed the "Set up a Firebase Cloud Messaging client app on Flutter" guide and add the following:

  • Enable the entitlement for "Push notifications" in Xcode
  • Enable the entitlement for "Background fetch" and the "Remote notifications" in Xcode
  • Created a Apple Push Notifications service (APNs) Key in Apple Developer Account
  • Upload this same Apple Push Notifications service (APNs) Key to Firebase environments "Staging" and "Production"
  • In Staging uploaded Key to iOS dev app and iOS Staging app
  • In Production environment upload the key to iOS Prod app

Handling of Android notifications if the app is in the foreground, is still open. See #540

Summary by CodeRabbit

  • New Features

    • Added support for background notifications and fetch operations in iOS app
    • Enhanced messaging repository with improved message handling and logging
  • iOS Configuration

    • Updated app entitlements for development environment
    • Configured code signing and background modes
  • Version Update

    • Incremented app version to 1.1.14+35

@KarinBerg KarinBerg linked an issue Jan 28, 2025 that may be closed by this pull request
1 task
Copy link

vercel bot commented Jan 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
public ⬜️ Ignored (Inspect) Visit Preview Jan 31, 2025 10:22am

Copy link

coderabbitai bot commented Jan 28, 2025

📝 Walkthrough

Walkthrough

This pull request introduces iOS-specific configuration changes for a mobile application, focusing on push notification handling and entitlements. The modifications include updating the project's code signing settings, adding background notification support, configuring the APNs development environment, and enhancing the messaging repository's message handling logic. The changes aim to improve the app's notification capabilities and project configuration.

Changes

File Change Summary
recipients_app/ios/Runner.xcodeproj/project.pbxproj Added Runner.entitlements file reference and updated CODE_SIGN_ENTITLEMENTS for multiple build configurations
recipients_app/ios/Runner/Info.plist Added UIBackgroundModes with remote-notification and fetch values
recipients_app/ios/Runner/Runner.entitlements Added aps-environment with development value
recipients_app/lib/data/repositories/messaging_repository.dart Refactored messaging handling with new methods for background, foreground, and initial message processing
recipients_app/pubspec.yaml Bumped version from 1.1.14+33 to 1.1.14+35

Sequence Diagram

sequenceDiagram
    participant App
    participant FirebaseMessaging
    participant BackgroundHandler
    
    App->>FirebaseMessaging: Initialize Notifications
    FirebaseMessaging->>BackgroundHandler: Register Background Handler
    
    alt Foreground Message
        FirebaseMessaging->>App: _handleForegroundMessage()
    else Background Message
        FirebaseMessaging->>BackgroundHandler: _firebaseMessagingBackgroundHandler()
    else Initial Message
        App->>BackgroundHandler: _handleInitialMessage()
    end
Loading

Possibly related PRs

Suggested labels

mobile

Suggested reviewers

  • andrashee
  • mkue
  • MDikkii
  • novas1r1
  • ssandino

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@KarinBerg KarinBerg marked this pull request as ready for review January 31, 2025 10:37
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
recipients_app/lib/data/repositories/messaging_repository.dart (4)

44-45: Consider renaming _handleBackgroundMessage when bound to onMessageOpenedApp.

The naming might be confusing since onMessageOpenedApp is specifically triggered upon user interaction.


63-66: Implement or remove the TODO for foreground notifications.

Would you like help implementing local notifications while the app is open?


69-73: Implement or remove the TODO for background notifications.

Consider finalizing this logic or removing the placeholder code.


75-78: Streamline logic for initial messages.

You could unify _handleInitialMessage with background/foreground handlers if similar steps are needed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ecf5cf5 and ff3fc5e.

📒 Files selected for processing (5)
  • recipients_app/ios/Runner.xcodeproj/project.pbxproj (11 hunks)
  • recipients_app/ios/Runner/Info.plist (1 hunks)
  • recipients_app/ios/Runner/Runner.entitlements (1 hunks)
  • recipients_app/lib/data/repositories/messaging_repository.dart (3 hunks)
  • recipients_app/pubspec.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • recipients_app/pubspec.yaml
🔇 Additional comments (10)
recipients_app/ios/Runner/Runner.entitlements (1)

5-6: LGTM! APNs environment is correctly configured.

The aps-environment is set to development which is appropriate for development and testing push notifications.

recipients_app/ios/Runner/Info.plist (1)

66-70: LGTM! Background modes are properly configured.

The required background modes for push notifications are correctly set:

  • remote-notification: Enables receiving push notifications
  • fetch: Allows background data refresh
recipients_app/ios/Runner.xcodeproj/project.pbxproj (1)

38-38: LGTM! Entitlements are properly configured across all build configurations.

The Runner.entitlements file is:

  1. Added to the project references
  2. Included in the Runner group
  3. Configured in all build configurations (dev, stage, prod)

Also applies to: 128-128, 445-445, 535-535, 622-622, 714-714, 804-804, 891-891, 978-978, 1123-1123, 1160-1160

recipients_app/lib/data/repositories/messaging_repository.dart (7)

6-12: Great job ensuring background handler is not removed by tree shaking.

This function is correctly annotated with @pragma("vm:entry-point") and simply logs and delegates to MessagingRepository.logRemoteMessage.


22-22: Be cautious about logging the FCM token.

Access tokens can be sensitive. Consider omitting them or logging only in debug mode.


32-33: Avoid printing current FCM token in production logs.

Similar to line 22, tokens might be considered sensitive. Restrict logging or sanitize the token before logging.


35-38: Good approach for handling terminated-state messages.

This logic ensures that messages arriving before the app is started are handled properly.


41-42: Using onBackgroundMessage is aligned with best practices.

This enables background handling without blocking the main thread.


47-49: Foreground notification handling is set up correctly.

You’ve correctly wired a listener to _handleForegroundMessage.


85-97: Review log data to prevent accidental PII exposure.

logRemoteMessage prints various fields of the RemoteMessage. Confirm these fields do not contain sensitive user data in production builds.

@KarinBerg KarinBerg self-assigned this Jan 31, 2025
@KarinBerg KarinBerg added the mobile Issues concerning Mobile App label Jan 31, 2025
@KarinBerg KarinBerg added this to the App v1.1.14 milestone Jan 31, 2025
@KarinBerg KarinBerg merged commit 323d37d into main Feb 3, 2025
16 checks passed
@KarinBerg KarinBerg deleted the karin/538-mobile-app-feature-enable-push-notifications-for-ios branch February 3, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Issues concerning Mobile App
Projects
Development

Successfully merging this pull request may close these issues.

[Mobile App Feature]: Enable push notifications for iOS
3 participants