Source: https://fyno.docs.pageloop.ai/sd-ks/mobile-push/react-native-push-sdk/ios-push

# IOS specific configuration

To enable push notifications for iOS, you need to configure specific capabilities and handle the necessary app delegate code. Let's walk through these steps.

1. **Update iOS pods**

   Run `pod install` in the ios folder of your React Native application to install/update the pod dependencies.
2. **Add capabilities in iOS application**
   1. Open your React Native project in Xcode.

   2. Inside the **Targets** section, select your app target, and go to **Signing & Capabilities**.

   3. Click on **+ Capability** and add **Push Notifications** and **Background Modes** capabilities.
      ![](/images/react_ios_1.jpeg)
      ![](/images/react_ios_2.jpeg)

   4. In Background Modes, select the Remote Notifications option. This is required to receive background push notifications. Learn more about background notifications [here](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app).
3. **Register for push notification in the AppDelegate file**

   To handle push notifications in your iOS app, add the following code to the `AppDelegate` file:
   1. Import the required packages:
   #### AppDelegate.mm
   ```objc
   #import "AppDelegate.h"
   #import <React/RCTBundleURLProvider.h>
   #import <UserNotifications/UserNotifications.h>
   #import <fyno/fyno-Swift.h>
   ```
   #### AppDelegate.swift
   ```swift
   import UIKit
   import React
   import React_RCTAppDelegate
   import ReactAppDependencyProvider
   import fyno_push_ios
   ```
   2. If you are using Firebase Cloud Messaging (FCM), add the Firebase imports:
   #### AppDelegate.mm
   ```objc
   #import <FirebaseMessaging/FirebaseMessaging.h>
   #import <FirebaseCore/FirebaseCore.h> 
   ```
   #### AppDelegate.swift
   ```swift
   import FirebaseCore
   import FirebaseMessaging
   ```
   3. Make the required changes in the AppDelegate file
   #### AppDelegate.mm
   ```objc
   @interface AppDelegate () <UNUserNotificationCenterDelegate>
   @property (nonatomic, strong) fyno *fynosdk;
   @end
   @implementation AppDelegate
   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
   {
     ...
     UNUserNotificationCenter.currentNotificationCenter.delegate = self.fynosdk;
     self.fynosdk = [fyno app];
     [self.fynosdk registerForRemoteNotifications];
     ...
   }
   - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
     NSLog(@"Failed to register for remote notifications: %@", error.localizedDescription);
   }
   - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
     // Send the device token to fynoServer
     [self.fynosdk setdeviceTokenWithDeviceToken:deviceToken];
   }

   ...
   ```
   #### AppDelegate.swift
   ```swift
   class AppDelegate: UIResponder, UIApplicationDelegate {
   ...

   let fynosdk = fyno.app

   ..
   func application(
     _ application: UIApplication,
     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
   ) -> Bool {
     ...
     
     self.fynosdk.registerForRemoteNotifications()
     fynosdk.requestNotificationAuthorization { _ in 
     ...
     
     return true
   }

   func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
     print("Failed to register for remote notifications: \(error.localizedDescription)")
   }

   func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
     fynosdk.setdeviceToken(deviceToken: deviceToken)
   }

   ```
4. **Add a Notification Service Extension**

   To ensure rich push notifications and proper handling of incoming messages, add a `Notification Service Extension` to your iOS project:
   1. In Xcode go to **File** > **New** > **Target**.
   2. Select `Notification Service Extension` from the template list.
   3. Provide a product name, select your development team, choose the appropriate language, and click Finish.
   ![](/images/react_ios_2.png)
   ![](/images/react_ios_4.png)

   Replace the contents of the generated `NotificationService` file with the following code:
   #### NotificationService.m
   ```objc
   #import "NotificationService.h"
   #import <fyno/fyno-Swift.h>
   #import <FirebaseCore/FirebaseCore.h>
   #import <FirebaseMessaging/FirebaseMessaging.h>

   @interface NotificationService ()
     @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
     @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
   @end

   @implementation NotificationService
     - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
       [[fyno app] handleDidReceive:request withContentHandler:contentHandler];
     }

     - (void)serviceExtensionTimeWillExpire {
       // Called just before the extension will be terminated by the system.
       // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
       self.contentHandler(self.bestAttemptContent);
     }
   @end

   ```
   #### NotificationService.swift
   ```swift
   import UserNotifications
   import UIKit
   import fyno

   class NotificationService: UNNotificationServiceExtension {
       var contentHandler: ((UNNotificationContent) -> Void)?
       var bestAttemptContent: UNMutableNotificationContent?

       override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
           fyno.app.handleDidReceive(request, withContentHandler: contentHandler)
       }

       override func serviceExtensionTimeWillExpire() {
           if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
               contentHandler(bestAttemptContent)
           }
       }
   } 
   ```
5. **Add Fyno SDK to the Notification Service Extension**

   In order for the Notification Service Extension to be able to access **fyno**, you will have to import it by following the below steps:
   #### Objective-C
   1. In Xcode, select your Notification Service Extension target.
   2. Under `Frameworks and Libraries`, click on the **+** button.
      ![](/images/react_ios_5.png)
   3. Select the framework named **fyno.xcframework** and click on **Add**
      ![](/images/react_ios_6.png)
   #### Swift
   1. In Xcode, select your Notification Service Extension target.

   2. Under `Frameworks and Libraries`, click on the **+** button.
      ![](/images/react_ios_5.png)

   3. Under `Add Other`, click on the `Add Package Dependency`.
      ![](/images/react_ios_7.png)

   4. Search for `https://github.com/fynoio/ios-sdk` in the text box.

   5. Select and add the `ios-sdk` package.
      ![](/images/react_ios_8.png)

   6. Ensure the target is set to the Notification Service Extension you created, then click `Add Package`.
      ![](/images/react_ios_9.png)

> [!TIP]
>
> You have successfully integrated Fyno's React Native Push Notification SDK into your application. Go ahead and test the integration by sending a push notification using [Notification Events](./events-overview)
