Skip to content

chore: fix flutter v2 PN docs #7580

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

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Choose _FCM_ when promoted:

```console
? Choose the push notification channel to enable.
APNS |  Apple Push Notifications
❯ FCM | » Firebase Push Notifications
In-App Messaging
Email
SMS

? Provide your pinpoint resource name:
`yourPinpointResourceName`

? Apps need authorization to send analytics events. Do you want to allow guests and unauthenticated users to send analytics events? (we recommend you allow this when getting started) (Y/n)
'Y'

```

The CLI will prompt for your _Server Key_, paste the **Token** you copied while [setting up push notification services](/gen1/[platform]/prev/build-a-backend/push-notifications/set-up-push-service/).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Push Notifications are delivered via Firebase Cloud Messaging (FCM). In order to use FCM, you need to register your app on the Firebase console. See [Setting up push notification services](/gen1/[platform/prev/build-a-backend/push-notifications/set-up-push-service/) for more information.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Setting Up FCM for Push Notifications

Push notifications for Android apps are sent using Firebase Cloud Messaging (FCM). Before you can send push notifications to Android devices, you must perform the following steps:

- [Create a Firebase project](https://firebase.google.com/docs/cloud-messaging/android/first-message#create_a_firebase_project).
- [Register your app with Firebase](https://firebase.google.com/docs/cloud-messaging/android/first-message#register_your_app_with_firebase)
- [Add a Firebase configuration file](https://firebase.google.com/docs/cloud-messaging/android/first-message#add_a_firebase_configuration_file)

Next, you will need to access your **ServerKey** (Referred to as **ApiKey** in the CLI setup):

- Open the [Firebase console](https://console.firebase.google.com/).
- Choose your Firebase project.
- Select the gear icon located in the top left hand corner of your screen, then select **Project settings**.

![image](/images/push-notifications/setup-fcm/project-settings.png)

- Select the **Cloud Messaging** tab.
- Select the three vertical dots next to **Cloud Messaging API (Legacy)**, then select **Manage API in Google Cloud Console**. ![The three dot menu button is circled in the cloud messaging tab.](/images/push-notifications/firebaseconsole.png)

![image](/images/push-notifications/setup-fcm/manage-api.png)

- In the new tab, select the **Enable** button.
- Return to the previous page and refresh it.
- Copy the **Server key** token

![image](/images/push-notifications/setup-fcm/server-id.png)

Return to [Provisioning resources through CLI](/gen1/[platform]/prev/build-a-backend/push-notifications/set-up-push-notifications/#provisioning-resources-through-cli) with the copied **Token**
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ The app badge count, when set, can be seen on your app's icon on a user's device

Use `getBadgeCount` to get the current app badge count. You might need to do this to calculate the value when setting the badge count.

import flutterGetBadgeCount from '/src/fragments/lib/push-notifications/flutter/app_badge_count/get-badge-count.mdx';
import reactNativeGetBadgeCount from '/src/fragments/lib/push-notifications/react-native/app_badge_count/get-badge-count.mdx';
import flutterGetBadgeCount from '/src/fragments/lib-v1/push-notifications/flutter/app_badge_count/get-badge-count.mdx';
import reactNativeGetBadgeCount from '/src/fragments/lib-v1/push-notifications/react-native/app_badge_count/get-badge-count.mdx';

<Fragments
fragments={{
Expand All @@ -23,8 +23,8 @@ import reactNativeGetBadgeCount from '/src/fragments/lib/push-notifications/reac

Use `setBadgeCount` to set the current app badge count. Setting the badge count to `0` (zero) will remove the badge from your app's icon.

import flutterSetBadgeCount from '/src/fragments/lib/push-notifications/flutter/app_badge_count/set-badge-count.mdx';
import reactNativeSetBadgeCount from '/src/fragments/lib/push-notifications/react-native/app_badge_count/set-badge-count.mdx';
import flutterSetBadgeCount from '/src/fragments/lib-v1/push-notifications/flutter/app_badge_count/set-badge-count.mdx';
import reactNativeSetBadgeCount from '/src/fragments/lib-v1/push-notifications/react-native/app_badge_count/set-badge-count.mdx';

<Fragments
fragments={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Amplify currently supports adding images to your notifications, but there are so

2. Add `AmplifyUtilsNotifications` to the extension you created above.

import flutterAddNotificationsPod from '/src/fragments/lib/push-notifications/flutter/enable_rich_notifications/add-notifications-pod.mdx';
import reactNativeAddNotificationsPod from '/src/fragments/lib/push-notifications/react-native/enable_rich_notifications/add-notifications-pod.mdx';
import flutterAddNotificationsPod from '/src/fragments/lib-v1/push-notifications/flutter/enable_rich_notifications/add-notifications-pod.mdx';
import reactNativeAddNotificationsPod from '/src/fragments/lib-v1/push-notifications/react-native/enable_rich_notifications/add-notifications-pod.mdx';

<Fragments
fragments={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
You should have [completed the CLI and project setup steps.](/[platform]/start/project-setup/prerequisites/)
You should have [completed the CLI and project setup steps.](/gen1/[platform]/prev/start/project-setup/prerequisites/)

<BlockSwitcher>
<Block name="iOS">

An application targeting at least iOS 13.0, using Xcode 14.1 or later.

import apnsPreReq from '/src/fragments/lib/push-notifications/ios/getting_started/apns-pre-req.mdx';
import apnsPreReq from '/src/fragments/lib-v1/push-notifications/ios/getting_started/apns-pre-req.mdx';

<Fragments fragments={{ flutter: apnsPreReq, 'react-native': apnsPreReq }} />

Expand All @@ -18,7 +18,7 @@ Using Amplify Push Notifications with APNs requires the following capabilities:

To add these capabilities:

import iosSetEntitlements from '/src/fragments/lib/push-notifications/ios/getting_started/ios-set-entitlements.mdx';
import iosSetEntitlements from '/src/fragments/lib-v1/push-notifications/ios/getting_started/ios-set-entitlements.mdx';

<Fragments fragments={{ flutter: iosSetEntitlements, 'react-native': iosSetEntitlements }} />

Expand All @@ -27,7 +27,7 @@ import iosSetEntitlements from '/src/fragments/lib/push-notifications/ios/gettin

An application targeting at least Android SDK API level 24.

import fcmPreReq from '/src/fragments/lib/push-notifications/android/getting_started/fcm-pre-req.mdx';
import fcmPreReq from '/src/fragments/lib-v1/push-notifications/android/getting_started/fcm-pre-req.mdx';

<Fragments fragments={{ flutter: fcmPreReq, 'react-native': fcmPreReq }} />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
The Push Notifications category allows you to integrate push notifications in your app with Amazon Pinpoint targeting, campaign, and journey management support. You can segment your users, trigger push notifications to your app, and record metrics in Pinpoint when users receive or open notifications. Amazon Pinpoint helps you to create messaging campaigns and journeys targeted to specific user segments or demographics and collect interaction metrics with push notifications.

import reactNativeExpoCallout from '/src/fragments/lib/push-notifications/react-native/getting_started/expo-callout.mdx';
import reactNativeExpoCallout from '/src/fragments/lib-v1/push-notifications/react-native/getting_started/expo-callout.mdx';

<Fragments fragments={{ 'react-native': reactNativeExpoCallout }} />

## Prerequisites

import androidPreReq from '/src/fragments/lib/push-notifications/android/getting_started/10_pre_req.mdx';
import crossPlatformPreReq from '/src/fragments/lib/push-notifications/common/getting_started/cross-platform-prereq.mdx';
import iosPreReq from '/src/fragments/lib/push-notifications/ios/getting_started/10_pre_req.mdx';
import crossPlatformPreReq from '/src/fragments/lib-v1/push-notifications/common/getting_started/cross-platform-prereq.mdx';

<Fragments
fragments={{
android: androidPreReq,
flutter: crossPlatformPreReq,
swift: iosPreReq,
'react-native': crossPlatformPreReq
}}
/>

import iosSetEntitlements from '/src/fragments/lib/push-notifications/ios/getting_started/20_set_entitlements.mdx';

<Fragments fragments={{ swift: iosSetEntitlements }} />

import iosCreateAppDelegate from '/src/fragments/lib/push-notifications/ios/getting_started/30_create_app_delegate.mdx';

<Fragments fragments={{ swift: iosCreateAppDelegate }} />

## Set up backend resources

To use Push Notifications with Amplify, you have the option to either have the Amplify CLI setup resources for you, or you can use an existing Amazon Pinpoint resource in your AWS account.

<BlockSwitcher>
<Block name="Amplify CLI">

> Prerequisite: [Install and configure the Amplify CLI](/gen1/[platform]/tools/cli/start/set-up-cli/)
> Prerequisite: [Install and configure the Amplify CLI](/gen1/[platform]/prev/tools/cli/start/set-up-cli/)

<Callout warning>

Expand All @@ -48,33 +36,25 @@ To start provisioning push notification resources in the backend, go to your pro
amplify add notifications
```

import androidCliResources from '/src/fragments/lib/push-notifications/android/getting_started/20_cli_resources.mdx';
import iosCliResources from '/src/fragments/lib/push-notifications/ios/getting_started/40_cli_resources.mdx';
import flutterCliResources from '/src/fragments/lib/push-notifications/flutter/getting_started/20_cli_resources.mdx';
import reactNativeCliResources from '/src/fragments/lib/push-notifications/react-native/getting_started/20_cli_resources.mdx';
import flutterCliResources from '/src/fragments/lib-v1/push-notifications/flutter/getting_started/20_cli_resources.mdx';
import reactNativeCliResources from '/src/fragments/lib-v1/push-notifications/react-native/getting_started/20_cli_resources.mdx';

<Fragments
fragments={{
android: androidCliResources,
flutter: flutterCliResources,
swift: iosCliResources,
'react-native': reactNativeCliResources
}}
/>

</Block>
<Block name="Existing resources">

import androidExistingResources from '/src/fragments/lib/push-notifications/android/getting_started/30_existing_resources.mdx';
import flutterExistingResources from '/src/fragments/lib/push-notifications/flutter/getting_started/30_existing_resources.mdx';
import iosExistingResources from '/src/fragments/lib/push-notifications/ios/getting_started/50_existing_resources.mdx';
import reactNativeExistingResources from '/src/fragments/lib/push-notifications/react-native/getting_started/30_existing_resources.mdx';
import flutterExistingResources from '/src/fragments/lib-v1/push-notifications/flutter/getting_started/30_existing_resources.mdx';
import reactNativeExistingResources from '/src/fragments/lib-v1/push-notifications/react-native/getting_started/30_existing_resources.mdx';

<Fragments
fragments={{
android: androidExistingResources,
flutter: flutterExistingResources,
swift: iosExistingResources,
'react-native': reactNativeExistingResources
}}
/>
Expand All @@ -84,36 +64,28 @@ import reactNativeExistingResources from '/src/fragments/lib/push-notifications/

## Install Amplify Libraries

import androidInstallLib from '/src/fragments/lib/push-notifications/android/getting_started/40_install_lib.mdx';
import flutterInstallLib from '/src/fragments/lib-v1/push-notifications/flutter/getting-started/40_install_lib.mdx';
import iosInstallLib from '/src/fragments/lib/push-notifications/ios/getting_started/60_install_lib.mdx';
import reactNativeInstallLib from '/src/fragments/lib/push-notifications/react-native/getting_started/40_install_lib.mdx';
import flutterInstallLib from '/src/fragments/lib-v1/push-notifications/flutter/getting_started/40_install_lib.mdx';
import reactNativeInstallLib from '/src/fragments/lib-v1/push-notifications/react-native/getting_started/40_install_lib.mdx';

<Fragments
fragments={{
android: androidInstallLib,
flutter: flutterInstallLib,
swift: iosInstallLib,
'react-native': reactNativeInstallLib
}}
/>

import reactNativeIntegrateNativeModule from '/src/fragments/lib/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx';
import reactNativeIntegrateNativeModule from '/src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx';

<Fragments fragments={{ 'react-native': reactNativeIntegrateNativeModule }} />

## Initialize Amplify Push Notifications

import androidInitPN from '/src/fragments/lib/push-notifications/android/getting_started/50_init_push_notifications.mdx';
import flutterInitPN from '/src/fragments/lib/push-notifications/flutter/getting_started/50_init_push_notifications.mdx';
import iosInitPN from '/src/fragments/lib/push-notifications/ios/getting_started/70_init_push_notifications.mdx';
import reactNativeInitPN from '/src/fragments/lib/push-notifications/react-native/getting_started/60_init_push_notifications.mdx';
import flutterInitPN from '/src/fragments/lib-v1/push-notifications/flutter/getting_started/50_init_push_notifications.mdx';
import reactNativeInitPN from '/src/fragments/lib-v1/push-notifications/react-native/getting_started/60_init_push_notifications.mdx';

<Fragments
fragments={{
android: androidInitPN,
flutter: flutterInitPN,
swift: iosInitPN,
'react-native': reactNativeInitPN
}}
/>
23 changes: 4 additions & 19 deletions src/fragments/lib-v1/push-notifications/common/identify-user.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ This call identifies the current user (which could be unauthenticated or authent

## Get the user ID from Amplify Auth

import androidGetUser from '/src/fragments/lib/push-notifications/android/identify_user/10_get_auth_user.mdx';
import flutterGetUser from '/src/fragments/lib/push-notifications/flutter/identify_user/10_get_auth_user.mdx';
import iosGetUser from '/src/fragments/lib/push-notifications/ios/identify_user/10_get_auth_user.mdx';
import reactNativeGetUser from '/src/fragments/lib/push-notifications/react-native/identify_user/10_get_auth_user.mdx';
import flutterGetUser from '/src/fragments/lib-v1/push-notifications/flutter/identify_user/10_get_auth_user.mdx';
import reactNativeGetUser from '/src/fragments/lib-v1/push-notifications/react-native/identify_user/10_get_auth_user.mdx';

<Fragments
fragments={{
android: androidGetUser,
flutter: flutterGetUser,
swift: iosGetUser,
'react-native': reactNativeGetUser
}}
/>
Expand All @@ -20,23 +16,12 @@ import reactNativeGetUser from '/src/fragments/lib/push-notifications/react-nati

Once you have a string that identifies the current user (either from the Auth category as shown above or through your own application logic), you can identify the user to Amazon Pinpoint with the following:

import androidSendToPinpoint from '/src/fragments/lib/push-notifications/android/identify_user/20_send_to_pinpoint.mdx';
import flutterSendToPinpoint from '/src/fragments/lib/push-notifications/flutter/identify_user/20_send_to_pinpoint.mdx';
import iosSendToPinpoint from '/src/fragments/lib/push-notifications/ios/identify_user/20_send_to_pinpoint.mdx';
import reactNativeSendToPinpoint from '/src/fragments/lib/push-notifications/react-native/identify_user/20_send_to_pinpoint.mdx';
import flutterSendToPinpoint from '/src/fragments/lib-v1/push-notifications/flutter/identify_user/20_send_to_pinpoint.mdx';
import reactNativeSendToPinpoint from '/src/fragments/lib-v1/push-notifications/react-native/identify_user/20_send_to_pinpoint.mdx';

<Fragments
fragments={{
android: androidSendToPinpoint,
flutter: flutterSendToPinpoint,
swift: iosSendToPinpoint,
'react-native': reactNativeSendToPinpoint
}}
/>

import androidSendWithProfile from '/src/fragments/lib/push-notifications/android/identify_user/30_send_to_pinpoint_profile.mdx';
import iosSendWithProfile from '/src/fragments/lib/push-notifications/ios/identify_user/30_send_to_pinpoint_profile.mdx';

<Fragments
fragments={{ android: androidSendWithProfile, swift: iosSendWithProfile }}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Push notifications are powerful engagement tools for your users as they can be d
- **Background state**: Your app is still running but is not currently active and visible. The user is usually on the home screen or in another app.
- **Terminated state**: Your app is no longer running, even in the background. The user can initiate this by swiping your app away in the app switcher.

import notificationLifecycle from '/src/fragments/lib/push-notifications/common/interact_with_notifications/notification-lifecycle.mdx';
import notificationLifecycle from '/src/fragments/lib-v1/push-notifications/common/interact_with_notifications/notification-lifecycle.mdx';

<Fragments
fragments={{
Expand All @@ -13,7 +13,7 @@ import notificationLifecycle from '/src/fragments/lib/push-notifications/common/
}}
/>

import notificationReceived from '/src/fragments/lib/push-notifications/common/interact_with_notifications/notification-received.mdx';
import notificationReceived from '/src/fragments/lib-v1/push-notifications/common/interact_with_notifications/notification-received.mdx';

<Fragments
fragments={{
Expand All @@ -22,7 +22,7 @@ import notificationReceived from '/src/fragments/lib/push-notifications/common/i
}}
/>

import notificationOpened from '/src/fragments/lib/push-notifications/common/interact_with_notifications/notification-opened.mdx';
import notificationOpened from '/src/fragments/lib-v1/push-notifications/common/interact_with_notifications/notification-opened.mdx';

<Fragments
fragments={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Before delving into details about the various functions Amplify provides, it can

For the purposes of this guide, we will simplify the terminology as follows

import flutterTerminology from '/src/fragments/lib/push-notifications/flutter/interact_with_notifications/terminology.mdx';
import reactNativeTerminology from '/src/fragments/lib/push-notifications/react-native/interact_with_notifications/terminology.mdx';
import flutterTerminology from '/src/fragments/lib-v1/push-notifications/flutter/interact_with_notifications/terminology.mdx';
import reactNativeTerminology from '/src/fragments/lib-v1/push-notifications/react-native/interact_with_notifications/terminology.mdx';

<Fragments
fragments={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ To help you with this, Amplify provides two ways of handling notifications being

Add `onNotificationOpened` listeners to respond to a push notification being opened while your app is in a foreground **or** background state.

import flutterOnNotificationOpened from '/src/fragments/lib/push-notifications/flutter/interact_with_notifications/on-notification-opened.mdx';
import reactNativeOnNotificationOpened from '/src/fragments/lib/push-notifications/react-native/interact_with_notifications/on-notification-opened.mdx';
import flutterOnNotificationOpened from '/src/fragments/lib-v1/push-notifications/flutter/interact_with_notifications/on-notification-opened.mdx';
import reactNativeOnNotificationOpened from '/src/fragments/lib-v1/push-notifications/react-native/interact_with_notifications/on-notification-opened.mdx';

<Fragments
fragments={{
Expand All @@ -33,8 +33,8 @@ Calling `getLaunchNotification` _consumes_ the launch notification and will yiel
- Another notification was opened while your app was running (either in foreground or background)
- Your app was brought back to the foreground by some other means (e.g. user tapped the app icon)

import flutterGetLaunchNotification from '/src/fragments/lib/push-notifications/flutter/interact_with_notifications/get-launch-notification.mdx';
import reactNativeGetLaunchNotification from '/src/fragments/lib/push-notifications/react-native/interact_with_notifications/get-launch-notification.mdx';
import flutterGetLaunchNotification from '/src/fragments/lib-v1/push-notifications/flutter/interact_with_notifications/get-launch-notification.mdx';
import reactNativeGetLaunchNotification from '/src/fragments/lib-v1/push-notifications/react-native/interact_with_notifications/get-launch-notification.mdx';

<Fragments
fragments={{
Expand Down
Loading
Loading