> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-angular-v5-docs-update.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Marking Delivered From Push Notification

> Guide to marking messages as delivered using push notification payload with Notification Service Extension.

<Accordion title="AI Integration Quick Reference">
  * **Requires:** UNNotificationServiceExtension target in your app
  * **Purpose:** Mark messages delivered even when app is in background/terminated
  * **Implementation:** Call `CometChat.markAsDelivered()` in notification extension
  * **Parse payload:** Extract message ID, sender ID, receiver type from notification
  * **Related:** [Delivery & Read Receipts](/sdk/ios/delivery-read-receipts) · [Push Notifications](/notifications/push-overview)
</Accordion>

Implementing the capability to mark a message as "delivered" through a push notification payload confirms to the sender that their message has reached its intended recipient, enhancing the overall user experience.

Setting up Mark as delivered from push notification in iOS requires a Notification extension in your app project.

<Note>
  If you already have a Notification extension on your project then you can skip the first part of creating a new extension and use the one you have.
</Note>

### Setting up Notification extension

1. Navigate to your project's target section and click on the plus iOS

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-angular-v5-docs-update/ZgtHsaNQApHuht0z/images/bebacc7e-n3luq9beoss2m2rrq441yvklq0qdgdo8l7o5p68hpjd35g14axybs6sqotkj8jba-3987e443fd24ea0c1e32af8f6d7d3699.png?fit=max&auto=format&n=ZgtHsaNQApHuht0z&q=85&s=b5cc8453e3f449686061be171e86b05f" width="3006" height="1974" data-path="images/bebacc7e-n3luq9beoss2m2rrq441yvklq0qdgdo8l7o5p68hpjd35g14axybs6sqotkj8jba-3987e443fd24ea0c1e32af8f6d7d3699.png" />
</Frame>

2. Then Scroll down, select Notification Service Extension and click on the next.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-angular-v5-docs-update/xB2gtIZtet1FaUV2/images/36a79bad-g0r2llvb74jts8wprgrtv7xcc0cp579lj4d8l1jea4iaxomzsadmf4rtilhba2ft-defa21a2b91f8a868993e213cd8689ed.png?fit=max&auto=format&n=xB2gtIZtet1FaUV2&q=85&s=2a168dcbfe60ae6ce45fbfaaa8a2390e" width="1628" height="1214" data-path="images/36a79bad-g0r2llvb74jts8wprgrtv7xcc0cp579lj4d8l1jea4iaxomzsadmf4rtilhba2ft-defa21a2b91f8a868993e213cd8689ed.png" />
</Frame>

3. Give it a name and click finish

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-angular-v5-docs-update/hS2ODI36gzqSC7wJ/images/b40d4fe3-hw3bdemnkitlfd9717xrasevp39hwa4og8w8ncyasybi7a0m07dj9xd0c8wletx1-95f99134fe857f52f59bca2194fd3276.png?fit=max&auto=format&n=hS2ODI36gzqSC7wJ&q=85&s=97f51439330008b605f44c3a0eafc646" width="1628" height="1214" data-path="images/b40d4fe3-hw3bdemnkitlfd9717xrasevp39hwa4og8w8ncyasybi7a0m07dj9xd0c8wletx1-95f99134fe857f52f59bca2194fd3276.png" />
</Frame>

* Your notification service extension is ready now, you can see that in the target list. Now we will create app group for the extension. This app group will be needed to share user default between the main application and notification service extension.

4. Click on the notification service extension name on the target list, then select Signing & Capabilities, then click on "+ Capability" from the top. Make sure All is selected besides it.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-angular-v5-docs-update/T0aTXbhtWmYnVWC0/images/adf243b8-uxobr5po4lg6c9dmfpmxkgwmqrzc3izcr0ebo4o8vbrlizcgp7pivdqzgoxeoq5z-ff82bb13573e5aa62eadb84d4f88641a.png?fit=max&auto=format&n=T0aTXbhtWmYnVWC0&q=85&s=c0657874f1d41d88d25a614d00619a30" width="3006" height="1974" data-path="images/adf243b8-uxobr5po4lg6c9dmfpmxkgwmqrzc3izcr0ebo4o8vbrlizcgp7pivdqzgoxeoq5z-ff82bb13573e5aa62eadb84d4f88641a.png" />
</Frame>

5. Then search for App Group and click on it. You can see a section of the app group section must have been added on the 'Signing & Capabilities'.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-angular-v5-docs-update/UlRk7SYYn7zdv3js/images/58046089-tj0q9z3hhcyk5oumprf3q9ypu6vyol2nl2bgofw6vs2drdqen2lz3ul7dmr7p0hf-7f701199b876e8a957f12b828c72b844.png?fit=max&auto=format&n=UlRk7SYYn7zdv3js&q=85&s=51ebe11cb443f94d297fef17f620b2b0" width="1586" height="1216" data-path="images/58046089-tj0q9z3hhcyk5oumprf3q9ypu6vyol2nl2bgofw6vs2drdqen2lz3ul7dmr7p0hf-7f701199b876e8a957f12b828c72b844.png" />
</Frame>

6. Select any of the suggested app group ID or you can add your own ID by clicking on the plus icon. Till this step app group is added on the notification extension target and app group is selected.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-angular-v5-docs-update/hS2ODI36gzqSC7wJ/images/bcbd0d7e-63gqeee1j6iwj7ynaebzxtulkzrbekkirzsq4k7egemcu0rxalf9cawqr9rc5v1s-fce3f8e40e188f635733a5455840cf0b.png?fit=max&auto=format&n=hS2ODI36gzqSC7wJ&q=85&s=3aca45b900b13b7a73dc26a99400e29e" width="1836" height="398" data-path="images/bcbd0d7e-63gqeee1j6iwj7ynaebzxtulkzrbekkirzsq4k7egemcu0rxalf9cawqr9rc5v1s-fce3f8e40e188f635733a5455840cf0b.png" />
</Frame>

7. Now add the Capability of App Group on the main app's target as well. Repeat the same steps from step 4 for your main app target.
8. Select the same group ID that you selected on the notification extension target's app group.

<Note>
  Make sure the app ID is exactly the same on both the notification extension target and the main app target.
</Note>

9. Lastly, add CometChatSDK in your notification extension target in the pod file.

<Tabs>
  <Tab title="Swift">
    ```ruby theme={null}
    # Uncomment the next line to define a global platform for your project
    # platform :ios, '12.0'

    target 'CometChatSwift' do

      pod 'CometChatSDK', '4.1.0'
      pod 'CometChatCallsSDK', '4.2.2'

    end

    # add your notification extension name here
    target 'NotificationExtension' do

      pod 'CometChatSDK', '4.0.67'

    end
    ```
  </Tab>
</Tabs>

All the setup is done, let's see some code now.

## Code for Mark as read

1. Navigate to the CometChat initialization code in your project and add the group ID that you selected on app groups on the AppSettingsBuilder.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let appSettings = AppSettings.AppSettingsBuilder()
                    .subscribePresenceForAllUsers()
                    .setRegion(region: Constants.region)
                    .setExtensionGroupID(id: "group.com.comechatcalls.appgroup") //add you app group ID here
                    .build()
    ```
  </Tab>
</Tabs>

2. Navigate to your notification extension group and open its swift file.
3. Import CometChatSDK and call these 2 functions in the `didReceive(_:withContentHandler:)` function.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
            self.contentHandler = contentHandler
            bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

            CometChat.setExtensionGroupID(id: "group.com.comechatcalls.appgroup") //add you group id

            if let bestAttemptContent = bestAttemptContent {

                CometChat.markAsDelivered(withNotificationPayload: bestAttemptContent.userInfo) //send the payload here

                contentHandler(bestAttemptContent)
            }
        }
    ```
  </Tab>
</Tabs>

Run your notification extension by selecting the notification extension target from the run target on the top.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-angular-v5-docs-update/xXJ8R25bxTI-kBC4/images/0e77a2b1-nqjmfzzns44ay0dttcwyldax2ty22al3madpljdu57yhdolln45cfx7pa89vnn6k-e1fc7f626a5adf1f5838c528d49f79be.png?fit=max&auto=format&n=xXJ8R25bxTI-kBC4&q=85&s=716f9cf5a90bafc0fbf82ec8ed652d42" width="1620" height="592" data-path="images/0e77a2b1-nqjmfzzns44ay0dttcwyldax2ty22al3madpljdu57yhdolln45cfx7pa89vnn6k-e1fc7f626a5adf1f5838c528d49f79be.png" />
</Frame>

<Note>
  Run the main app target first and make sure you are receiving notifications there. And then run the notification extension target.
</Note>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Delivery & Read Receipts" icon="check-double" href="/sdk/ios/delivery-read-receipts">
    Mark messages as delivered and read
  </Card>

  <Card title="Push Notifications" icon="bell" href="/notifications/push-overview">
    Set up push notifications for your iOS app
  </Card>

  <Card title="Increment Badge Count" icon="circle-plus" href="/sdk/ios/increment-app-icon-badge-count">
    Update app icon badge from push notifications
  </Card>

  <Card title="Remove Delivered Notifications" icon="trash" href="/sdk/ios/remove-delivered-notifications">
    Programmatically remove delivered notifications
  </Card>
</CardGroup>
