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

feat(firebase_messaging): roadmap rework #4012

Merged
merged 40 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
aff7197
Merge pull request #47 from FirebaseExtended/master
Ehesp Jul 30, 2020
0e98060
Merge pull request #48 from FirebaseExtended/master
Ehesp Jul 30, 2020
58c19bf
Merge pull request #54 from FirebaseExtended/master
Ehesp Aug 6, 2020
2f06ff1
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Aug 13, 2020
bf8339c
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Aug 25, 2020
90b3f47
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Aug 27, 2020
fa1d5cf
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Sep 3, 2020
131c396
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Sep 7, 2020
dcd0181
Merge branch 'master' of https://github.com/invertase/flutterfire
Salakar Sep 7, 2020
82021af
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Sep 22, 2020
c2ace6b
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Oct 5, 2020
2ad3da6
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Oct 7, 2020
076aa78
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Oct 7, 2020
192ee74
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Oct 27, 2020
fa30f2a
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Oct 27, 2020
6a75682
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Oct 28, 2020
10c87a1
Merge branch 'master' of https://github.com/FirebaseExtended/flutterfire
Salakar Oct 29, 2020
8bc8508
feat(firebase_messaging): v1 rework (#76)
Ehesp Nov 2, 2020
4328fb3
Update packages/firebase_messaging/firebase_messaging/example/test_dr…
Salakar Nov 3, 2020
c9df3f4
Update packages/firebase_messaging/firebase_messaging/README.md
Salakar Nov 3, 2020
620b421
Update packages/firebase_messaging/firebase_messaging/example/lib/per…
Salakar Nov 3, 2020
ea34d5d
Update packages/firebase_messaging/firebase_messaging/lib/src/messagi…
Salakar Nov 3, 2020
b579c82
Update packages/firebase_messaging/firebase_messaging/test/firebase_m…
Salakar Nov 3, 2020
e217b2c
Update packages/firebase_messaging/firebase_messaging/test/firebase_m…
Salakar Nov 3, 2020
c83da1e
Update packages/firebase_messaging/firebase_messaging_platform_interf…
Salakar Nov 3, 2020
172f4ae
Update packages/firebase_messaging/firebase_messaging_platform_interf…
Salakar Nov 3, 2020
5f48131
refactor: fix platform interface tests
Salakar Nov 3, 2020
e9bd897
refactor: fix firebase_messaging tests
Salakar Nov 3, 2020
242cd02
refactor: remove instanceFor - not supported on messaging
Salakar Nov 3, 2020
dfc116c
tests: dart define a bool to determine if running in CI
Salakar Nov 3, 2020
bc29a64
docs: update `requestPermission` code docs to clarify platform specif…
Salakar Nov 3, 2020
22527da
tests: call init app before tests
Salakar Nov 3, 2020
8656853
tests: fix e2e tests
Salakar Nov 3, 2020
1573175
test: setup `apple` workflow job
Salakar Nov 3, 2020
4d8de94
tests: fix e2e test
Salakar Nov 3, 2020
1531da8
docs: add v1 embedding guide
Salakar Nov 3, 2020
62221da
docs: finish migration guide for messaging
Salakar Nov 3, 2020
61beead
docs: migration guide formatting & typos
Salakar Nov 3, 2020
007ebe5
docs: add messaging change log
Salakar Nov 3, 2020
ea6714d
docs: add changelog to CHANGELOG.md file
Salakar Nov 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/firebase_messaging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,24 @@ jobs:
profile: Nexus 5X
script: ./.github/workflows/scripts/drive-example.sh android

ios:
apple:
runs-on: macos-latest
timeout-minutes: 30
timeout-minutes: 40
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 0
- name: "Install Flutter"
run: ./.github/workflows/scripts/install-flutter.sh stable
run: ./.github/workflows/scripts/install-flutter.sh dev
- name: "Install Tools"
run: ./.github/workflows/scripts/install-tools.sh
- name: "Build Example"
run: |
./.github/workflows/scripts/install-tools.sh
flutter config --enable-macos-desktop
- name: "Build iOS Example"
run: ./.github/workflows/scripts/build-example.sh ios
- name: "Drive Example"
- name: "Drive iOS Example"
run: ./.github/workflows/scripts/drive-example.sh ios
- name: "Build MacOS Example"
run: ./.github/workflows/scripts/build-example.sh macos
- name: "Drive MacOS Example"
run: ./.github/workflows/scripts/drive-example.sh macos
6 changes: 3 additions & 3 deletions .github/workflows/scripts/build-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ melos bootstrap
if [ "$ACTION" == "android" ]
then
melos exec -c 1 --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" -- \
flutter build apk --debug --target="$TARGET_FILE"
flutter build apk --debug --target="$TARGET_FILE" --dart-define=CI=true
MELOS_EXIT_CODE=$?
pkill dart || true
pkill java || true
Expand All @@ -21,7 +21,7 @@ fi
if [ "$ACTION" == "ios" ]
then
melos exec -c 1 --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" -- \
flutter build ios --no-codesign --simulator --debug --target="$TARGET_FILE"
flutter build ios --no-codesign --simulator --debug --target="$TARGET_FILE" --dart-define=CI=true
exit
fi

Expand All @@ -31,6 +31,6 @@ then
echo "TODO: Skipping macOS testing due to Flutter dev branch issue."
exit
melos exec -c 1 --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" -- \
flutter build macos --debug --target="$TARGET_FILE"
flutter build macos --debug --target="$TARGET_FILE" --dart-define=CI=true
exit
fi
8 changes: 4 additions & 4 deletions .github/workflows/scripts/drive-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ then
# Sleep to allow emulator to settle.
sleep 15
melos exec -c 1 --fail-fast --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" --dir-exists=test_driver -- \
flutter drive --no-pub --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart
flutter drive --no-pub --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart --dart-define=CI=true
exit
fi

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

Expand All @@ -43,6 +43,6 @@ then
melos bootstrap
chromedriver --port=4444 &
melos exec -c 1 --scope="$FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE" --dir-exists=web -- \
flutter drive --release --no-pub --verbose-system-logs --browser-name=chrome --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart
flutter drive --release --no-pub --verbose-system-logs --browser-name=chrome --target=./test_driver/MELOS_PARENT_PACKAGE_NAME_e2e.dart --dart-define=CI=true
exit
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.atom/
.idea/
.vscode/*
.melos_tool/*
!.vscode/tasks.json
!.vscode/settings.json

Expand Down
196 changes: 157 additions & 39 deletions README.md

Large diffs are not rendered by default.

Binary file added docs/_assets/ios-notification-images-step-1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_assets/ios-notification-images-step-2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_assets/ios-notification-images-step-3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_assets/ios-provisional-notification.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
---
title: iOS Messaging Integration
sidebar_label: iOS Integration
description: iOS requires additional configuration steps to be completed before you can receive messages.
title: FCM via APNs Integration
sidebar_label: Apple Integration
description: iOS & macOS require additional configuration steps to be completed before you can receive messages.
---

Integrating the Cloud Messaging plugin on iOS devices requires additional setup before your devices receive messages.
:::caution
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.
:::

Integrating the Cloud Messaging plugin on iOS & macOS devices requires additional setup before your devices receive messages.
There are also a number of prerequisites which are required to be able to enable messaging:

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

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

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

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

### Enable Background Modes
### Enable Background Modes (iOS only)

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

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

## Linking APNs with FCM (iOS)
## Linking APNs with FCM

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

1. Click the "Identifiers" side menu item.
2. Click the plus button to register a App Identifier.
2. Click the plus button to register a App Identifier.
3. Select the "App IDs" option and click "Continue".
4. Select the "App" type option and click "Continue".

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

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

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

1. Select the project.
2. Select the project target.
3. Assign the provisioning profile.
1. Select the project (usually called 'Runner') in the left hand side project navigator.
2. Select the project target under the 'Targets' heading, usually called 'Runner'.
3. Select the Signing & Capabilities tab.
3. Assign the provisioning profile in the 'Signing' section.

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

## (Advanced, Optional) Allowing Notification Images

> 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).
On Apple devices, in order for incoming FCM [Notifications](notifications.mdx) to display images from the FCM payload, you must add an additional notification
service extension. This is not a required step.

### Step 1 - Add a notification service extension

- From Xcode top menu go to: **File > New > Target...**
- A modal will present a list of possible targets, scroll down or use the filter to select "Notification Service Extension". Press Next.
- Add a product name (use `ImageNotification` to follow along) and click **Finish**.
- Enable the scheme by clicking **Activate**.

![Xcode - Add a notification service extension](ios-notification-images-step-1.gif)

### Step 2 - Add target to the Podfile

Ensure that your new extension has access to Firebase/Messaging pod by adding it in the Podfile:

- From the Navigator open the Podfile: Pods > Podfile
- Scroll down to the bottom of the file and add:
```ruby
target 'ImageNotification' do
pod 'Firebase/Messaging'
end
```

- Install or update your pods using `pod install` from the `ios` and/or `macos` directory.

![Xcode - Add target to the Podfile](ios-notification-images-step-2.gif)

### Step 3 - Use the extension helper

At this point everything should still be running normally. This is the final step which is invoking the extension helper.

- From the navigator select your `ImageNotification` extension
- Open the `NotificationService.m` file
- At the top of the file import `FirebaseMessaging.h` right after the `NotificationService.h` as shown below:
```diff
#import "NotificationService.h"
+ #import "FirebaseMessaging.h"
```
- Replace everything from line 25 to 28 with the extension helper:
```diff
- // Modify the notification content here...
- self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];

- self.contentHandler(self.bestAttemptContent);
+ [[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent withContentHandler:contentHandler];
```

![Xcode - Use the extension helper](ios-notification-images-step-3.gif)

### Step 4

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.

## Next steps

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

> 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).
View the [Usage documentation](usage.mdx) to get started.
Loading