Skip to content

chore: add AppDelegate updates example in Swift (react-native >= 0.77) #8272

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 2 commits into from
Feb 28, 2025
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
Expand Up @@ -17,6 +17,39 @@ npx pod-install

### Update your Application Delegate

Depending on the React Native version you’re using, you need to use Objective-C or Swift code snippets to update your application.

<BlockSwitcher>

<Block name=">= 0.77.0">

Locate and open your `AppDelegate.swift` file in your text editor. You should find it in your React Native project under `/ios/<your-project-name>`.

At the top of your `AppDelegate`, import Amplify Push Notifications:

```swift
import ReactAppDependencyProvider
import AmplifyRTNPushNotification // <- add this line

...
```

In the body of your `AppDelegate`, add the following two methods:

```swift
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
AmplifyPushNotification.didRegisterForRemoteNotifications(withDeviceToken: deviceToken)
}

override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
AmplifyPushNotification.didReceiveRemoteNotification(userInfo, withCompletionHandler: completionHandler)
}
```

</Block>

<Block name="< 0.77.0">

Locate and open your `AppDelegate.m` or `AppDelegate.mm` file in your text editor. You should find it in your React Native project under `/ios/<your-project-name>`

At the top of your `AppDelegate`, import Amplify Push Notifications:
Expand All @@ -39,3 +72,7 @@ In the body of your `AppDelegate`, add the following two methods:
[AmplifyPushNotification didReceiveRemoteNotification:userInfo withCompletionHandler:completionHandler];
}
```

</Block>

</BlockSwitcher>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@ npx pod-install

### Update your Application Delegate

Depending on the React Native version you’re using, you need to use Objective-C or Swift code snippets to update your Application.

<BlockSwitcher>

<Block name=">= 0.77.0">

Locate and open your `AppDelegate.swift` file in your text editor. You should find it in your React Native project under `/ios/<your-project-name>`.

At the top of your `AppDelegate`, import Amplify Push Notifications:

```swift
import ReactAppDependencyProvider
import AmplifyRTNPushNotification // <- add this line

...
```

In the body of your `AppDelegate`, add the following two methods:

```swift
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
AmplifyPushNotification.didRegisterForRemoteNotifications(withDeviceToken: deviceToken)
}

override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
AmplifyPushNotification.didReceiveRemoteNotification(userInfo, withCompletionHandler: completionHandler)
}
```

</Block>

<Block name="< 0.77.0">

Locate and open your `AppDelegate.m` or `AppDelegate.mm` file in your text editor. You should find it in your React Native project under `/ios/<your-project-name>`

At the top of your `AppDelegate`, import Amplify Push Notifications:
Expand All @@ -39,3 +72,7 @@ In the body of your `AppDelegate`, add the following two methods:
[AmplifyPushNotification didReceiveRemoteNotification:userInfo withCompletionHandler:completionHandler];
}
```

</Block>

</BlockSwitcher>