Skip to content

Commit e72668d

Browse files
HuiSFcshfang
andauthored
chore: add AppDelegate updates example in Swift (react-native >= 0.77) (#8272)
* chore: add AppDelegate updates example in Swift (react-native >= 0.77) * Update src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx Co-authored-by: Chris F <[email protected]> --------- Co-authored-by: Chris F <[email protected]>
1 parent 10054a4 commit e72668d

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

src/fragments/lib-v1/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx

+37
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,39 @@ npx pod-install
1717

1818
### Update your Application Delegate
1919

20+
Depending on the React Native version you’re using, you need to use Objective-C or Swift code snippets to update your application.
21+
22+
<BlockSwitcher>
23+
24+
<Block name=">= 0.77.0">
25+
26+
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>`.
27+
28+
At the top of your `AppDelegate`, import Amplify Push Notifications:
29+
30+
```swift
31+
import ReactAppDependencyProvider
32+
import AmplifyRTNPushNotification // <- add this line
33+
34+
...
35+
```
36+
37+
In the body of your `AppDelegate`, add the following two methods:
38+
39+
```swift
40+
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
41+
AmplifyPushNotification.didRegisterForRemoteNotifications(withDeviceToken: deviceToken)
42+
}
43+
44+
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
45+
AmplifyPushNotification.didReceiveRemoteNotification(userInfo, withCompletionHandler: completionHandler)
46+
}
47+
```
48+
49+
</Block>
50+
51+
<Block name="< 0.77.0">
52+
2053
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>`
2154

2255
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:
3972
[AmplifyPushNotification didReceiveRemoteNotification:userInfo withCompletionHandler:completionHandler];
4073
}
4174
```
75+
76+
</Block>
77+
78+
</BlockSwitcher>

src/fragments/lib/push-notifications/react-native/getting_started/50_integrate_native_modules.mdx

+37
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,39 @@ npx pod-install
1717

1818
### Update your Application Delegate
1919

20+
Depending on the React Native version you’re using, you need to use Objective-C or Swift code snippets to update your Application.
21+
22+
<BlockSwitcher>
23+
24+
<Block name=">= 0.77.0">
25+
26+
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>`.
27+
28+
At the top of your `AppDelegate`, import Amplify Push Notifications:
29+
30+
```swift
31+
import ReactAppDependencyProvider
32+
import AmplifyRTNPushNotification // <- add this line
33+
34+
...
35+
```
36+
37+
In the body of your `AppDelegate`, add the following two methods:
38+
39+
```swift
40+
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
41+
AmplifyPushNotification.didRegisterForRemoteNotifications(withDeviceToken: deviceToken)
42+
}
43+
44+
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
45+
AmplifyPushNotification.didReceiveRemoteNotification(userInfo, withCompletionHandler: completionHandler)
46+
}
47+
```
48+
49+
</Block>
50+
51+
<Block name="< 0.77.0">
52+
2053
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>`
2154

2255
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:
3972
[AmplifyPushNotification didReceiveRemoteNotification:userInfo withCompletionHandler:completionHandler];
4073
}
4174
```
75+
76+
</Block>
77+
78+
</BlockSwitcher>

0 commit comments

Comments
 (0)