# Integrate offline push (/en/realtime-media/im/build/notifications-and-event-handling/offline-push/integrate-test/ios)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

Follow this guide to integrate and test push notifications in your environment.

    ## Prerequisites [#prerequisites-1]

    Before proceeding, ensure that you meet the following requirements:

    * You have initialized the Chat SDK. For details, see [SDK quickstart](../../../get-started-sdk).
    * You understand the call frequency limit of the Chat APIs supported by different pricing plans as described in [Limitations](../../limitations).

    ## Integrate APNs push [#integrate-apns-push]

    This section guides you through how to integrate APNs with Chat. To integrate APNs into Chat, follow these steps:

    ### 1. Create a push certificate on the Apple Developer Platform [#1-create-a-push-certificate-on-the-apple-developer-platform]

    APNs supports p8 and p12 certificates. The Agora server needs your APNs certificate to communicate with APNs and send push notifications to the client.

    The following steps describe how to create a p12 certificate on [Apple's developer platform](https://developer.apple.com/):

    1. Apply for the Certificate Signing Request (CSR) file.

    2. Open the Keychain Access app on your device and select **Keychain Access** > **Certificate Assistant** > **Request a Certificate from a Certificate Authority**.

    3. In the **Certificate Assistant** dialog box, fill in the **User Email Address** and **Common Name**, select **Saved to disk** for **Request is**, click **Continue**, and add a storage path to save the file.

       ![push\_apns\_ca](https://assets-docs.agora.io/images/im/push_apns_ca.png)

    4. The CSR file `CertificateSigningRequest.certSigningRequest` is generated under the storage path.

    ### 2. Create an App ID [#2-create-an-app-id]

    1. Log in to [iOS Developer Center](https://developer.apple.com/cn/)，choose **Account** > **Certificates, Identifiers & Profiles** > **Identifiers**.
    2. On the **Identifiers*&#x2A; tab, click the &#x2A;*+** icon to the right of **Identifiers**.
    3. On the **Register a new identifier** page, select **App IDs** and click **Continue**.
    4. For **Select a type**, select **App** and click **Continue**.
    5. On the **Register an App ID** page, configure the following fields:
       * **Description**: Description of the App ID.
       * **Bundle ID**: Can be set to **com.YourCompany.YourProjectName**.
       * **Capabilities**: Choose **Push Notification**.
    6. Make sure the information is correct and click **Register**.

    ### 3. Create push notification certificates [#3-create-push-notification-certificates]

    Create certificates for development and production environments, respectively:

    1. On the **Identifiers** tab, select the App ID created in the previous step.
    2. On the **Edit your App ID Configuration** page, find **Push Notifications** and click **Configure**.
    3. In the **Apple Push Notification service SSL Certificates** dialog box, click **Create Certificate** to create a push certificate for development or production environments.
    4. On the **Create a New Certificate** page, select **iOS** as the **Platform**, upload the CSR file created in step 1, and click **Continue**.
    5. On the **Download Your Certificate** page, click **Download** to generate the [APNs](https://help.apple.com/xcode/mac/current/?spm=a2c4g.11186623.0.0.14864088B1zf4p#/dev80c6204ec) certificate.

    ### 4. Generate the push certificate [#4-generate-the-push-certificate]

    1. Double-click to import the push certificate created in Keychain in previous steps.
    2. Open **Keychain Access** , select **login** > **Certificates**, find the imported certificate, right-click and select the certificate to export as a `.p12` file, and set the certificate key.

    ### 5. Generate the Provisioning Profile file [#5-generate-the-provisioning-profile-file]

    1. Open [iOS Developer Center](https://developer.apple.com/cn/)，select **Account** > **Certificates, Identifiers & Profiles** > \**Profiles*.
    2. On the **Provisioning*&#x2A; tab, click the &#x2A;*+** icon to the right of **Profiles**.
    3. On the **Register a New Provisioning Profile** page, select **iOS App Development** for **Development**, select **Ad Hoc** for **Distribution**, and click **Continue**.
       For the official version on the App Store, select **App Store** for **Distribution**.
    4. On the **Generate a Provisioning Profile** page, configure the following fields:
       * **App ID**: Enter the App ID created in step 2.
       * **Select Certificates**: Select the `.p12` file generated in step 4.
       * **Select Devices**: Select the device to be developed.
       * **Provisioning Profile Name**: Enter the Provisioning Profile file name.
    5. Confirm the information and click **Download** to generate the Provisioning Profile file.

    ### 6. Upload the APNs certificate in the [Agora Console](https://console.agora.io/v2) [#6-upload-the-apns-certificate-in-the-agora-console]

    After successfully logging in to the Chat SDK, you can configure the push policy for multi-device login use-cases and upload the APNs push certificate in [Agora Console](https://console.agora.io/v2).

    1. Log in to [Agora Console](https://console.agora.io/v2) and click **Project Management** in the left navigation bar.
    2. On the **Project Management** page, click **Config** in the **Action** column for the project that has Chat enabled.
    3. On the **Edit Project** page, in the **Features** area, click **Enable/Config** for **Chat**.
    4. On the project configuration page, select **Features** > **Push Certificate**.
    5. On the Push Certificate page, click **Add Push Certificate**. In the dialog box that pops up, select the **Apple** tab and configure the fields.

       <CalloutContainer type="info">
         <CalloutDescription>
           If you use FCM push, select the **Google** tab and configure the FCM push parameters.
         </CalloutDescription>
       </CalloutContainer>

       ![push\_apns\_add\_certificate](https://assets-docs.agora.io/images/im/push_apns_add_certificate.png)

    | Parameter                   | Type   | Required (Yes/No) | Description                                                                                                                                                                 |
    | :-------------------------- | :----- | :---------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | **Certificate Type**        |        | Yes               | Message push certificate type, currently supports **p8** and **p12**.                                                                                                       |
    | **Certificate Name**        | String | Yes               | The name of the message push certificate. Enter the name of the message push certificate.                                                                                   |
    | **Push Key**                | String | Yes               | Message push certificate key. Fill in the certificate key set when exporting the message push certificate file. Configure this parameter only when using a p12 certificate. |
    | **Upload Certificate**      | File   | Yes               | Click **Upload** to upload the message push certificate file.                                                                                                               |
    | **Key ID**                  | String | Yes               | Enter the Key ID of the push certificate. Configure this parameter only when using a p8 certificate.                                                                        |
    | \*\*TeamID \*\*             | String | Yes               | Enter the Team ID of the push certificate. Configure this parameter only when using a p8 certificate.                                                                       |
    | **Integration Environment** |        | Yes               | Integration environment:  - **Development**: Development environment;  - **Production**: Production environment.                                                            |
    | **Bundle ID**               | String | Yes               | The bundle ID. The bundle ID set when creating the App ID.                                                                                                                  |
    | **sound**                   | String | No                | The ringtone alert when the receiver receives the push notification.                                                                                                        |

    ### 7. Integrate APNs on the client [#7-integrate-apns-on-the-client]

    1. Open Xcode and select **Targets** > **Capability** > **Push Notifications** to enable push notification permission.

    2. Pass the certificate name to the SDK:

       ```objc
       #import

       - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
           // Apply for notification permission
           UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
               [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
                   if (granted) {
                       NSLog(@"request authorization succeed");
                   }
               }];

           // Register push
           [application registerForRemoteNotifications];

           // Initialize options and set App Key
           AgoraChatOptions *options = [AgoraChatOptions optionsWithAppkey:@"XXXX#XXXX"];

           // Fill in the name you set when uploading the certificate. Make sure the certificate name you set here is consistent with the certificate name you filled in on Agora Console.
           options.apnsCertName = @"PushCertName";

           [AgoraChatClient.sharedClient initializeSDKWithOptions:options];

           return YES;
       }
       ```

    3. Get the device token and pass it to the server.

    After the device token is registered, the iOS system will call back the device token to you in the following way. Pass the device token to the SDK.

    ```objc
    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
        [AgoraChatClient.sharedClient registerForRemoteNotificationsWithDeviceToken:deviceToken completion:^(AgoraChatError *aError) {
            if (aError) {
                NSLog(@"bind deviceToken error: %@", aError.errorDescription);
            }
        }];
    }
    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
        NSLog(@"Register Remote Notifications Failed");
    }
    ```

    ## Test APNs push [#test-apns-push]

    After integrating and enabling FCM, you can test whether the push feature is successfully integrated.

    Make sure your test device is a non-jail-broken iOS device. For more reliable testing, use a physical device.

    ### Test push notifications [#test-push-notifications-1]

    1. Log in to the app on your device and confirm that the device token is successfully bound.

       You can check the log or call [RESTful API for getting user details](..//en/api-reference/api-ref/im/user-system-registration#querying-a-user) to confirm whether the device token is successfully bound. If successful, there will be a `pushInfo` field under the `entities` field, and `pushInfo` will have relevant information such as `device_Id`, `device_token`, `notifier_name`, and others.

    2. Enable app notification bar permissions.

    3. Kill the application process.

    4. Send a test message in the [Agora Console](https://console.agora.io/v2).

       Select **Operation Management** > **User** in the left navigation bar. On the **Users** page, select **Send Admin Message** in the **Action** column for the corresponding user ID. In the dialog box that pops up, select the message type, enter the message content, and then click **Send** .

       <CalloutContainer type="info">
         <CalloutDescription>
           In the **Push Certificate** page, in the **Action** column of each certificate, click **More** and **Test** will appear. This is to directly call the third-party interface to push. The message sending test in the **Users** page first calls the Chat message sending interface and then the third-party interface when the conditions are met (that is, the user is offline, the push certificate is valid and bound to the device token).
         </CalloutDescription>
       </CalloutContainer>

    5. Check your device to see if it has received the push notification.

    ### Troubleshooting [#troubleshooting-1]

    In case of issues, take the following steps:

    1. Check whether APNs push is correctly integrated or enabled:

       Select **Operation Management** > **User** in the left navigation bar. On the **User Management** page, select **Push Certificate** in the **Action** column for the corresponding user ID. In the pop-up box, check whether the certificate name and device token are displayed correctly.

    2. Check whether the correct APNs certificate has been uploaded in [Agora Console](https://console.agora.io/v2) and the correct certificate environment has been set.

    3. Check whether the message was pushed in the chat room. Chat rooms do not support offline message push.

    4. Check whether online-only delivery is enabled (`AgoraChatMessage#deliverOnlineOnly = YES`). Messages set to be delivered only when the receiver is online will not be pushed.

    
  
      
  
      
  
