From 168f6fc65f0c7ef604351b93521cc2370469eb7b Mon Sep 17 00:00:00 2001 From: Hui Zhao Date: Thu, 27 Feb 2025 15:42:49 -0800 Subject: [PATCH 1/2] chore: add AppDelegate updates example in Swift (react-native >= 0.77) --- .../50_integrate_native_modules.mdx | 37 +++++++++++++++++++ .../50_integrate_native_modules.mdx | 37 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx b/src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx index 3db4fac5b55..61fb884ad4c 100644 --- a/src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx +++ b/src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx @@ -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. + + + + + +Locate and open your `AppDelegate.swift` file in your text editor. You should find it in your React Native project under `/ios/`. + +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) +} +``` + + + + + 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/` At the top of your `AppDelegate`, import Amplify Push Notifications: @@ -39,3 +72,7 @@ In the body of your `AppDelegate`, add the following two methods: [AmplifyPushNotification didReceiveRemoteNotification:userInfo withCompletionHandler:completionHandler]; } ``` + + + + diff --git a/src/fragments/lib/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx b/src/fragments/lib/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx index 03345435929..2174f65d74c 100644 --- a/src/fragments/lib/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx +++ b/src/fragments/lib/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx @@ -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. + + + + + +Locate and open your `AppDelegate.swift` file in your text editor. You should find it in your React Native project under `/ios/`. + +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) +} +``` + + + + + 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/` At the top of your `AppDelegate`, import Amplify Push Notifications: @@ -39,3 +72,7 @@ In the body of your `AppDelegate`, add the following two methods: [AmplifyPushNotification didReceiveRemoteNotification:userInfo withCompletionHandler:completionHandler]; } ``` + + + + From af15d3afb78ffe77fbcd7da635680368a85e6c1c Mon Sep 17 00:00:00 2001 From: Hui Zhao <10602282+HuiSF@users.noreply.github.com> Date: Fri, 28 Feb 2025 15:06:39 -0800 Subject: [PATCH 2/2] Update src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx Co-authored-by: Chris F <5827964+cshfang@users.noreply.github.com> --- .../getting_started/50_integrate_native_modules.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx b/src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx index 61fb884ad4c..38c4709f14f 100644 --- a/src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx +++ b/src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx @@ -17,7 +17,7 @@ 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. +Depending on the React Native version you’re using, you need to use Objective-C or Swift code snippets to update your application.