Skip to content
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
Binary file removed docs/images/identifiers.gif
Binary file not shown.
Binary file removed docs/images/runningApp.gif
Binary file not shown.
167 changes: 69 additions & 98 deletions docs/lib/push-notifications/fragments/js/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,16 @@ Push Notifications category is integrated with [AWS Amplify Analytics category](

2. Get your push messaging credentials for Android in Firebase console. [Click here for instructions](~/sdk/push-notifications/setup-push-service.md/q/platform/android).

3. Create a native link on a React Native app:
3. Install dependencies:

```bash
react-native init myapp
cd myapp
npm install aws-amplify && npm install @aws-amplify/pushnotification
react-native link @aws-amplify/pushnotification
react-native link amazon-cognito-identity-js # link if you need to Sign in into Cognito user pool
npm install aws-amplify @aws-amplify/pushnotification
```

That would install required npm modules and link React Native binaries.

Please note that linking `aws-amplify-react-native` but not completing the rest of the configuration steps could break your build process. Please be sure that you have completed all the steps before you build your app.

4. Add your push messaging credentials (API key and Sender ID) with Amplify CLI by using the following commands:
4. Add your push messaging credentials (Server key) with Amplify CLI by using the following commands:

```bash
cd myapp
amplify init
amplify add notifications
amplify push
```

Choose *FCM* when promoted:
Expand Down Expand Up @@ -73,33 +62,17 @@ Push Notifications category is integrated with [AWS Amplify Analytics category](

6. Open *android/build.gradle* file and perform following edits:

- Add *classpath 'com.google.gms:google-services:3.2.0'* in the `dependencies` under *buildscript*:
- Add `classpath("com.google.gms:google-services:4.3.3")` in the `dependencies` under `buildscript`:

```gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.2.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
```
Also update maven `url` as the following under *allprojects > repositories*. Revise *allprojects* to be:

```gradle
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url "https://maven.google.com"
}
}
...
classpath("com.google.gms:google-services:4.3.3")
...
}
}
```

7. Open *android/app/build.gradle* and perform following edits:
Expand All @@ -108,21 +81,25 @@ Push Notifications category is integrated with [AWS Amplify Analytics category](

```gradle
dependencies {
compile project(':@aws-amplify/pushnotification')
..
..
..
compile 'com.google.firebase:firebase-core:12.0.1'
compile 'com.google.firebase:firebase-messaging:12.0.1'
...
implementation "com.google.firebase:firebase-core:12.0.1"
implementation "com.google.firebase:firebase-messaging:12.0.1"
...
}
```
- Add following configuration to the bottom of the file:

```gradle
apply plugin: 'com.google.gms.google-services'
apply plugin: "com.google.gms.google-services"
```

8. Open *android/app/src/main/AndroidManifest.xml* file and add the following configuration into `application` element.
8. Open *android/gradle/wrapper/gradle-wrapper.properties* update the Gradle `distributionUrl`:

```properties
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
```

9. Open *android/app/src/main/AndroidManifest.xml* file and add the following configuration into `application` element.

```xml
<application ... >
Expand Down Expand Up @@ -155,12 +132,12 @@ Push Notifications category is integrated with [AWS Amplify Analytics category](
</application>
```

9. Configure Push Notifications category for your app as shown in [Configure your App](#configure-your-app) section.
10. Configure Push Notifications category for your app as shown in [Configure your App](#configure-your-app) section.

10. Run your app with `yarn` or with an appropriate run command.
11. Run your app:

```bash
npm start
npx react-native run-android
```

## Setup for iOS
Expand All @@ -169,25 +146,19 @@ Push Notifications category is integrated with [AWS Amplify Analytics category](

2. Setup iOS Push Notifications and create a p12 certificate as instructed here in [Amazon Pinpoint Developer Guide](https://docs.aws.amazon.com/pinpoint/latest/developerguide/apns-setup.html).

3. Create a native link on a React Native app:
3. Install dependencies and CocoaPods:

```bash
react-native init myapp
cd myapp
npm install
npm install aws-amplify \
@aws-amplify/pushnotification \
@react-native-community/push-notification-ios
cd ios && pod install
npm install aws-amplify @aws-amplify/pushnotification @react-native-community/push-notification-ios
```
```bash
npx pod-install
```

4. Enable notifications and add your p12 certificate with Amplify CLI by using the following commands:

```bash
cd myapp
amplify init
amplify add notifications
amplify push
```

Choose *APNS* when promoted:
Expand All @@ -200,31 +171,32 @@ Push Notifications category is integrated with [AWS Amplify Analytics category](
SMS
```

Choose *Certificate* when promoted:

```console
? Choose authentication method used for APNs
> Certificate
Key
```

The CLI will prompt for your *p12 certificate path*, enter it respectively.

5. Setup Xcode for push notification support by following the "Add Capabilities : Background Mode - Remote Notifications" and "Augment AppDelegate" sections found in the: [React Native Push Notifications Documentation](https://github.com/react-native-community/push-notification-ios)
5. Open project in Xcode and make updates for `@react-native-community/push-notification-ios`:
- [Add Capabilities : Background Mode - Remote Notifications](https://github.com/react-native-community/push-notification-ios#add-capabilities--background-mode---remote-notifications)
- [Augment `AppDelegate`](https://github.com/react-native-community/push-notification-ios#augment-appdelegate)

6. Update General App settings:

- Make sure you have logged in with your Apple Developer account on Xcode
- Set bundle identifier (with the one you create on your Apple Developer Account)
- Unselect **Automatically manage signing** under **Signing** section
- On Signing (Debug, Release) set the provisioning profile (created on your Apple Developer Account)

*Following screencast shows the required app settings in Xcode:*
<img src="~/images/identifiers.gif"/>
- Make sure you have logged in with your Apple Developer account on Xcode and have a Team selected for the target.

7. Configure Push Notification module for your app as shown in [Configure your App](#configure-your-app) section.

8. Run your app:
8. Run your app:

- On Xcode, select your device and run it first using as *Executable appName.app*. This will install the App on your device but it won't run it.
- Select **Ask on Launch** for *Executable* option on menu chain *Product > Schema > Edit Scheme > Run > Info*.
- Click *Run* button and select your app from the list.
- In case the build fails, try cleaning the project with *shift + command + k*.

*Following screencast shows the required app settings in Xcode:*
<img src="~/images/runningApp.gif" />
```bash
npx react-native run-ios --device
```

## Configure your App

Expand All @@ -236,36 +208,35 @@ If you don't have Analytics already enabled, see our [Analytics Developer Guide]

</amplify-callout>

First, import `PushNotification` module and configure it with `PushNotification.configure()`.

```javascript
import { PushNotificationIOS } from '@react-native-community/push-notification-ios';
import Analytics from '@aws-amplify/analytics';
import Amplify from 'aws-amplify';
import PushNotification from '@aws-amplify/pushnotification';
import { PushNotificationIOS } from '@react-native-community/push-notification-ios';
import awsconfig from './aws-exports';

// PushNotification need to work with Analytics
Analytics.configure({
// You configuration will come here...
});

PushNotification.configure({
appId: 'XXXXXXXXXXabcdefghij1234567890ab',
requestIOSPermissions: false, // OPTIONAL, defaults to true
});
Amplify.configure(awsconfig);
```

`requestIOSPermissions` is an optional boolean flag which specifies whether or not to automatically request push notifications permissions in iOS when calling `PushNotification.configure` for the first time. If not provided, it defaults to `true`. When set to `false`, you may later call the method `PushNotification.requestIOSPermissions` at the explicit point in your application flow when you want to prompt the user for permissions.
### Configuration Options

You can also use `aws-exports.js` file in case you have set up your backend with Amplify CLI.
- `requestIOSPermissions` is an optional boolean flag which specifies whether or not to automatically request push notifications permissions in iOS when calling `PushNotification.configure` for the first time. If not provided, it defaults to `true`. When set to `false`, you may later call the method `PushNotification.requestIOSPermissions` at the explicit point in your application flow when you want to prompt the user for permissions.
- `appId` is optional and *only* needed if `aws-exports` doesn't contain `aws_mobile_analytics_app_id` or you are manually configuring each category inside `Amplify.configure()`.

```javascript
import { PushNotificationIOS } from '@react-native-community/push-notification-ios';
import Analytics from '@aws-amplify/analytics';
import PushNotification from '@aws-amplify/pushnotification';
import awsconfig from './aws-exports';

// PushNotification need to work with Analytics
Analytics.configure(awsconfig);

PushNotification.configure(awsconfig);
Amplify.configure({
...awsconfig,
PushNotification: {
requestIOSPermissions: false
}
});
```
```javascript
Amplify.configure({
Auth: { /* ... */ },
Analytics: { /* ... */ },
PushNotification: {
appId: 'XXXXXXXXXXabcdefghij1234567890ab',
requestIOSPermissions: false
}
});
```
4 changes: 2 additions & 2 deletions docs/lib/push-notifications/fragments/js/overview.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
The Push Notifications category allows you to integrate push notifications in your app with Amazon Pinpoint targeting and campaign management support.
The Push Notifications category allows you to integrate push notifications in your app with Amazon Pinpoint targeting, campaign, and journey management support.

<amplify-callout>

Push Notifications are currently supported only for **React Native**. For handling Web Push Notifications with Service Workers, visit our [Service Workers Guide](~/lib/utilities/serviceworker.md#handling-a-push-notification).

</amplify-callout>

This guide provides step-by-step instructions to start working with push notifications in React Native with Amazon Pinpoint. Amazon Pinpoint helps you to monitor your app's usage, create messaging campaigns targeted to specific user segments or demographics, and collect interaction metrics with push notifications.
This guide provides step-by-step instructions to start working with push notifications in React Native with Amazon Pinpoint. Amazon Pinpoint helps you to monitor your app's usage, create messaging campaigns and journeys targeted to specific user segments or demographics, and collect interaction metrics with push notifications.

> Ensure you have [installed and configured the Amplify CLI and library](~/cli/start/install.md).

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PushNotification.onNotification((notification) => {
// Note that the notification object structure is different from Android and IOS
console.log('in app notification', notification);

// required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
// required on iOS only (see fetchCompletionHandler docs: https://github.com/react-native-community/push-notification-ios#finish)
notification.finish(PushNotificationIOS.FetchResult.NoData);
});

Expand Down