Skip to content

Commit a37c605

Browse files
SalakarEhesphelenafordkirstywilliams
authored
feat(firebase_messaging): roadmap rework (#4012)
Co-authored-by: ehesp <[email protected]> Co-authored-by: Helena Ford <[email protected]> Co-authored-by: Kirsty Williams <[email protected]> Co-authored-by: Salakar <[email protected]> Co-authored-by: Elliot Hesp <[email protected]>
1 parent c2dd1dd commit a37c605

File tree

213 files changed

+11005
-2982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+11005
-2982
lines changed

.github/workflows/firebase_messaging.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,24 @@ jobs:
3838
profile: Nexus 5X
3939
script: ./.github/workflows/scripts/drive-example.sh android
4040

41-
ios:
41+
apple:
4242
runs-on: macos-latest
43-
timeout-minutes: 30
43+
timeout-minutes: 40
4444
steps:
4545
- uses: actions/checkout@v1
4646
with:
4747
fetch-depth: 0
4848
- name: "Install Flutter"
49-
run: ./.github/workflows/scripts/install-flutter.sh stable
49+
run: ./.github/workflows/scripts/install-flutter.sh dev
5050
- name: "Install Tools"
51-
run: ./.github/workflows/scripts/install-tools.sh
52-
- name: "Build Example"
51+
run: |
52+
./.github/workflows/scripts/install-tools.sh
53+
flutter config --enable-macos-desktop
54+
- name: "Build iOS Example"
5355
run: ./.github/workflows/scripts/build-example.sh ios
54-
- name: "Drive Example"
56+
- name: "Drive iOS Example"
5557
run: ./.github/workflows/scripts/drive-example.sh ios
58+
- name: "Build MacOS Example"
59+
run: ./.github/workflows/scripts/build-example.sh macos
60+
- name: "Drive MacOS Example"
61+
run: ./.github/workflows/scripts/drive-example.sh macos

.github/workflows/scripts/build-example.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ melos bootstrap
1010
if [ "$ACTION" == "android" ]
1111
then
1212
melos exec -c 1 --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" -- \
13-
flutter build apk --debug --target="$TARGET_FILE"
13+
flutter build apk --debug --target="$TARGET_FILE" --dart-define=CI=true
1414
MELOS_EXIT_CODE=$?
1515
pkill dart || true
1616
pkill java || true
@@ -21,7 +21,7 @@ fi
2121
if [ "$ACTION" == "ios" ]
2222
then
2323
melos exec -c 1 --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" -- \
24-
flutter build ios --no-codesign --simulator --debug --target="$TARGET_FILE"
24+
flutter build ios --no-codesign --simulator --debug --target="$TARGET_FILE" --dart-define=CI=true
2525
exit
2626
fi
2727

@@ -31,6 +31,6 @@ then
3131
echo "TODO: Skipping macOS testing due to Flutter dev branch issue."
3232
exit
3333
melos exec -c 1 --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" -- \
34-
flutter build macos --debug --target="$TARGET_FILE"
34+
flutter build macos --debug --target="$TARGET_FILE" --dart-define=CI=true
3535
exit
3636
fi

.github/workflows/scripts/drive-example.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ then
77
# Sleep to allow emulator to settle.
88
sleep 15
99
melos exec -c 1 --fail-fast --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" --dir-exists=test_driver -- \
10-
flutter drive --no-pub --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart
10+
flutter drive --no-pub --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart --dart-define=CI=true
1111
exit
1212
fi
1313

@@ -22,7 +22,7 @@ then
2222
# Uncomment following line to have simulator logs printed out for debugging purposes.
2323
# xcrun simctl spawn booted log stream --predicate 'eventMessage contains "flutter"' &
2424
melos exec -c 1 --fail-fast --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" --dir-exists=test_driver -- \
25-
flutter drive -d \"$SIMULATOR\" --no-pub --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart
25+
flutter drive -d \"$SIMULATOR\" --no-pub --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart --dart-define=CI=true
2626
MELOS_EXIT_CODE=$?
2727
xcrun simctl shutdown "$SIMULATOR"
2828
exit $MELOS_EXIT_CODE
@@ -34,7 +34,7 @@ then
3434
echo "TODO: Skipping macOS testing due to Flutter dev branch issue."
3535
exit
3636
melos exec -c 1 --fail-fast --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" --dir-exists=test_driver -- \
37-
flutter drive -d macos --no-pub --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart
37+
flutter drive -d macos --no-pub --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart --dart-define=CI=true
3838
exit
3939
fi
4040

@@ -43,6 +43,6 @@ then
4343
melos bootstrap
4444
chromedriver --port=4444 &
4545
melos exec -c 1 --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" --dir-exists=web -- \
46-
flutter drive --release --no-pub --verbose-system-logs --browser-name=chrome --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart
46+
flutter drive --release --no-pub --verbose-system-logs --browser-name=chrome --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart --dart-define=CI=true
4747
exit
4848
fi

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.atom/
33
.idea/
44
.vscode/*
5+
.melos_tool/*
56
!.vscode/tasks.json
67
!.vscode/settings.json
78

README.md

Lines changed: 157 additions & 39 deletions
Large diffs are not rendered by default.
Loading
Loading
1.12 MB
Loading
172 KB
Loading

docs/messaging/ios-integration.mdx renamed to docs/messaging/apple-integration.mdx

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
---
2-
title: iOS Messaging Integration
3-
sidebar_label: iOS Integration
4-
description: iOS requires additional configuration steps to be completed before you can receive messages.
2+
title: FCM via APNs Integration
3+
sidebar_label: Apple Integration
4+
description: iOS & macOS require additional configuration steps to be completed before you can receive messages.
55
---
66

7-
Integrating the Cloud Messaging plugin on iOS devices requires additional setup before your devices receive messages.
7+
:::caution
8+
This guide applies to both iOS & macOS Flutter apps, repeat each step for the platforms you require. E.g. if you support iOS & macOS then you will need to integrate twice, once per platform Xcode project.
9+
:::
10+
11+
Integrating the Cloud Messaging plugin on iOS & macOS devices requires additional setup before your devices receive messages.
812
There are also a number of prerequisites which are required to be able to enable messaging:
913

1014
- You must have an active [Apple Developer Account](https://developer.apple.com/membercenter/index.action).
11-
- You must have a physical iOS device to receive messages.
15+
- For iOS; you must have a physical iOS device to receive messages.
1216
- Firebase Cloud Messaging integrates with the [Apple Push Notification service (APNs)](https://developer.apple.com/notifications/),
1317
however APNs only works with real devices.
1418

@@ -17,7 +21,7 @@ There are also a number of prerequisites which are required to be able to enable
1721
Before your application can start to receive messages, you must explicitly enable "Push Notifications" and "Background Modes"
1822
within Xcode.
1923

20-
Open your project workspace file via Xcode (`/ios/Runner.xcworkspace`). Once open, follow the steps below:
24+
Open your project workspace file via Xcode (`/{ios|macos}/Runner.xcworkspace`). Once open, follow the steps below:
2125

2226
1. Select your project.
2327
2. Select the project target.
@@ -38,7 +42,7 @@ Next the "Push Notifications" capability needs to be added to the project. This
3842
Once selected, the capability will be shown below the other enabled capabilities. If no option appears when searching, the
3943
capability may already be enabled.
4044

41-
### Enable Background Modes
45+
### Enable Background Modes (iOS only)
4246

4347
Next the "Background Modes" capability needs to be enabled, along with both the "Background fetch" and "Remote notifications" sub-modes.
4448
This can be added via the "Capability" option on the "Signing & Capabilities" tab:
@@ -55,7 +59,7 @@ Now ensure that both the "Background fetch" and the "Remote notifications" sub-m
5559

5660
![Xcode - Enabling Background Modes](https://images.prismic.io/invertase/3a618574-dd9f-4478-9f39-9834d142b2e5_xcode-background-modes-check.gif?auto=compress,format)
5761

58-
## Linking APNs with FCM (iOS)
62+
## Linking APNs with FCM
5963

6064
> Note: APNs is required for both `foreground` and `background` messaging to function correctly on iOS.
6165
@@ -99,7 +103,7 @@ application that you're developing.
99103
On the Apple Developer portal:
100104

101105
1. Click the "Identifiers" side menu item.
102-
2. Click the plus button to register a App Identifier.
106+
2. Click the plus button to register a App Identifier.
103107
3. Select the "App IDs" option and click "Continue".
104108
4. Select the "App" type option and click "Continue".
105109

@@ -127,7 +131,7 @@ A provisioning profile enables signed communicate between Apple and your applica
127131
real devices, a signed certificate ensures that the app being installed on a device is genuine and has the correct
128132
permissions enabled.
129133

130-
On the "Profiles" menu item, register a new Profile. Select the "iOS App Development" checkbox and click "Continue".
134+
On the "Profiles" menu item, register a new Profile. Select the "iOS App Development" (or macOS) checkbox and click "Continue".
131135

132136
If you followed [Step 2](#2-registering-an-app-identifier) correctly, your App Identifier will be available in the drop down
133137
provided:
@@ -146,15 +150,74 @@ real device (using Xcode). Back within Xcode, select your project target and sel
146150
If Xcode (via Preferences) is linked to your Apple Account, Xcode can automatically sync the profile created above. Otherwise,
147151
you must manually add the profile from the Apple Developer console:
148152

149-
1. Select the project.
150-
2. Select the project target.
151-
3. Assign the provisioning profile.
153+
1. Select the project (usually called 'Runner') in the left hand side project navigator.
154+
2. Select the project target under the 'Targets' heading, usually called 'Runner'.
155+
3. Select the Signing & Capabilities tab.
156+
3. Assign the provisioning profile in the 'Signing' section.
152157

153158
![Xcode - Assign provisioning profile](ios-xcode-assign-provisioning-profile.png)
154159

160+
## (Advanced, Optional) Allowing Notification Images
161+
162+
> If you want to know more about the specifics of this setup read the [official Firebase docs](https://firebase.google.com/docs/cloud-messaging/ios/send-image).
163+
164+
On Apple devices, in order for incoming FCM [Notifications](notifications.mdx) to display images from the FCM payload, you must add an additional notification
165+
service extension. This is not a required step.
166+
167+
### Step 1 - Add a notification service extension
168+
169+
- From Xcode top menu go to: **File > New > Target...**
170+
- A modal will present a list of possible targets, scroll down or use the filter to select "Notification Service Extension". Press Next.
171+
- Add a product name (use `ImageNotification` to follow along) and click **Finish**.
172+
- Enable the scheme by clicking **Activate**.
173+
174+
![Xcode - Add a notification service extension](ios-notification-images-step-1.gif)
175+
176+
### Step 2 - Add target to the Podfile
177+
178+
Ensure that your new extension has access to Firebase/Messaging pod by adding it in the Podfile:
179+
180+
- From the Navigator open the Podfile: Pods > Podfile
181+
- Scroll down to the bottom of the file and add:
182+
```ruby
183+
target 'ImageNotification' do
184+
pod 'Firebase/Messaging'
185+
end
186+
```
187+
188+
- Install or update your pods using `pod install` from the `ios` and/or `macos` directory.
189+
190+
![Xcode - Add target to the Podfile](ios-notification-images-step-2.gif)
191+
192+
### Step 3 - Use the extension helper
193+
194+
At this point everything should still be running normally. This is the final step which is invoking the extension helper.
195+
196+
- From the navigator select your `ImageNotification` extension
197+
- Open the `NotificationService.m` file
198+
- At the top of the file import `FirebaseMessaging.h` right after the `NotificationService.h` as shown below:
199+
```diff
200+
#import "NotificationService.h"
201+
+ #import "FirebaseMessaging.h"
202+
```
203+
- Replace everything from line 25 to 28 with the extension helper:
204+
```diff
205+
- // Modify the notification content here...
206+
- self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
207+
208+
- self.contentHandler(self.bestAttemptContent);
209+
+ [[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent withContentHandler:contentHandler];
210+
```
211+
212+
![Xcode - Use the extension helper](ios-notification-images-step-3.gif)
213+
214+
### Step 4
215+
216+
Your device can now display images in a notification by specifying the `imageUrl` option in your FCM payload. Keep in mind that a 300KB max image size is enforced by the device.
217+
155218
## Next steps
156219

157-
Once the above has been completed, you're ready to get started receiving messages on your iOS device for both
220+
Once the above has been completed, you're ready to get started receiving messages on your iOS and/or macOS device for both
158221
testing and production.
159222

160-
> Usage documentation will be available once the Firebase Firebase Cloud Messaging plugin update lands as part of the [FlutterFire roadmap](https://github.com/FirebaseExtended/flutterfire/issues/2582).
223+
View the [Usage documentation](usage.mdx) to get started.

0 commit comments

Comments
 (0)