# Subchannel unread count doesn't work for community channels

**URL:** https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290
**Category:** iOS
**Created:** [May 1, 2024, 11:46am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290 "2024-05-01T11:46:46Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![nadol](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@nadol](https://forum.social.plus/u/nadol)
#### Post date: [May 1, 2024, 11:46am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/1 "2024-05-01T11:46:46Z")

</div>

The unread count for community subchannels is always 0. I’m calling `client.enableUnreadCount()` after `AmityClient` is initialised. The total unread count is working fine:

```auto
.$totalUnreadCount
            .sink(receiveValue: {
                print("Total unread count \($0)")
            })
            .store(in: &cancellables)

```

and I’m getting real time updates, but when I try to read subchannel unread count then it’s always 0:

```auto
.getChannels(channelIds: channelIds)
            .observe { [weak self] liveCollection, _, error in
                    print("is unread enabled \(snapshot.isUnreadCountSupported)")
                    print("Subchannel unread count \(snapshot.subChannelsUnreadCount)")
}

```

the `isUnreadCountSupported` returns true

I’m using the open source version of amity for iOS, I’ve tested this on the latest version of the UIKit SDK as well as on the latest beta. My region is set to US

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [May 1, 2024, 11:57am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/2 "2024-05-01T11:57:26Z")

</div>

Hello @nadol, let us pass to the team to investigate this. Thank you.

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [May 2, 2024, 12:31pm UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/3 "2024-05-02T12:31:44Z")

</div>

@nadol Regarding the issue you encountered, we recommend that you review the sample project available at this link: [Sample Project](https://drive.google.com/file/d/1CiuOalLx9eUE8Ogz2OaXz6yVyvqm_GAZ/view?pli=1). For additional information, please refer to the [SDK v6.26.0 Unread Count Migration Guide](https://docs.amity.co/developers/migration-guides/sdk-v6.26.0-unread-count-migration-guide)

---

<div class="post-metadata">

### Author: ![nadol](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@nadol](https://forum.social.plus/u/nadol)
#### Post date: [May 2, 2024, 1:24pm UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/4 "2024-05-02T13:24:23Z")

</div>

@SocialPlus_Support Do you have any instructions on how to use this sample app? What api key should I use?

---

<div class="post-metadata">

### Author: ![nadol](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@nadol](https://forum.social.plus/u/nadol)
#### Post date: [May 2, 2024, 1:26pm UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/5 "2024-05-02T13:26:08Z")

</div>

@SocialPlus_Support when I try to use the `victimIOS` then I’m getting warning printed in the console:

```auto
[Sample App] register device with userId 'victimIOS' failed
[Sample App] register device failed Invalid API key

```

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [May 2, 2024, 1:49pm UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/6 "2024-05-02T13:49:19Z")

</div>

Hello @nadol you should be able to use your own environment - your userid and apikey.

Please let us know if you still face the issue.

---

<div class="post-metadata">

### Author: ![nadol](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@nadol](https://forum.social.plus/u/nadol)
#### Post date: [May 6, 2024, 1:06pm UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/7 "2024-05-06T13:06:20Z")

</div>

@SocialPlus_Support after investigating this issue it turns out that the unread counter works fine for channels created on iOS side, I pasted the code from the sample app for creating channels and then when I join the channels created on iOS side everything works. It doesn’t work for channels created on backend side. My colleague is going to share his code snippets today to show you how he creates the channels on backend side. We compared channels created on iOS and backend sides in admin panel and found no differences

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [May 7, 2024, 7:42am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/8 "2024-05-07T07:42:06Z")

</div>

@nadol Can I confirm that by “backend” you mean you created the channel from the console and the unread count did not work?

---

<div class="post-metadata">

### Author: ![nadol](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@nadol](https://forum.social.plus/u/nadol)
#### Post date: [May 7, 2024, 4:29pm UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/9 "2024-05-07T16:29:08Z")

</div>

@SocialPlus_Support No, I have a backend service which is responsible for creating channels and it’s using [Amity API](https://api-docs.amity.co/#/Channel%20V3/post_api_v3_channels) api to do so. Here’s a snippet from my colleague who’s responsible for the backend service showing how he creates the channel:

```auto
const response = await axios.post(
        CREATE_CHANNEL_URL,
        {
          channelId,
          type: "community",
          displayName: channelName,
          metadata: {},
          tags: [],
          userIds: [],
          isMuted: false,
          messageAutoDeleteEnabled: true,
          autoDeleteMessageByFlagLimit: 100,
          isPublic: true,
          notificationMode: "default"
        },
        {
          headers: { Authorization: `Bearer ${config.adminToken}` }
        }
      )

```

then on the iOS side I’m observing the channels, joining them and the unread counter doesn’t work.

But when I was testing stuff using the sample app you provided then I found out that when I create some dummy channels on iOS side just for testing purposes then the unread counter works.

```auto
    var token: AmityNotificationToken?
    func createChannel() {
        if let user = AmityUIKitManager.client.user?.snapshot {
            let builder = AmityCommunityChannelBuilder()

            builder.setUserIds([user.userId])
            builder.setDisplayName("Test channel")
            token?.invalidate()
            token = channelRepository.getChannel("test-id").observe({ [weak self] (channel, error) in
                guard let weakSelf = self else { return }
                if error != nil {
                    weakSelf.createNewCommiunityChannel(builder: builder)
                }
            })
        }
    }

    private func createNewCommiunityChannel(builder: AmityCommunityChannelBuilder) {
        AmityAsyncAwaitTransformer.toCompletionHandler(asyncFunction: channelRepository.createChannel, parameters: builder) { [weak self] channelObject, error in
            guard let weakSelf = self else { return }
            if let error = error {
                print("FAILED \(error)")
            }
            if let channelId = channelObject?.channelId, let subChannelId = channelObject?.defaultSubChannelId {
                print("CHANNEL CREATED")
            }
        }
    }

```

Can this be caused by the fact that when creating channels on the backend the userIds is not set? Later on I’m joining these channels on iOS side and I verified that the members count is greater than 0 for these channels. Or can you spot any other differences?

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [May 8, 2024, 6:17am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/10 "2024-05-08T06:17:51Z")

</div>

> [@nadol](#):
>
> after investigating this issue it turns out that the unread counter works fine for channels created on iOS side, I pasted the code from the sample app for creating channels and then when I join the channels created on iOS side everything works. It doesn’t work for channels created on backend side. My colleague is going to share his code snippets today to show you how he creates the channels on backend side. We compared channels created on iOS and backend sides in admin panel and found no differences

@nadol Let me pass this to check with my team.

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [May 8, 2024, 9:37am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/11 "2024-05-08T09:37:53Z")

</div>

@nadol Did you try setting the userid and reproducing the issue again?

---

<div class="post-metadata">

### Author: ![nadol](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@nadol](https://forum.social.plus/u/nadol)
#### Post date: [May 8, 2024, 11:16am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/12 "2024-05-08T11:16:14Z")

</div>

@SocialPlus_Support I just checked and it’s still not working

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [May 13, 2024, 1:42pm UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/13 "2024-05-13T13:42:09Z")

</div>

Hi @nadol our team is currently investigating this, we will keep you posted on any updates.

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [May 15, 2024, 11:31am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/14 "2024-05-15T11:31:47Z")

</div>

Hello @nadol , We have resolved the issue you encountered with the Subchannel Unreadcount. Please verify the fix at your earliest convenience and let us know if there are any further issues.

---

<div class="post-metadata">

### Author: ![nadol](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@nadol](https://forum.social.plus/u/nadol)
#### Post date: [May 24, 2024, 8:06am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/15 "2024-05-24T08:06:58Z")

</div>

In the meantime I switched to open source version of amity [GitHub - AmityCo/Amity-Social-Cloud-UIKit-iOS-OpenSource: Amity Social Cloud offers Chat and Social SDKs to streamline app development. Dive into our UI Kits and sample apps in our repositories to spark your creativity. To learn more, visit amity.co.](https://github.com/AmityCo/Amity-Social-Cloud-UIKit-iOS-OpenSource) How can I update the AmitySDK to latest version in such case? Or do I have to update something else?

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [May 24, 2024, 12:19pm UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/16 "2024-05-24T12:19:30Z")

</div>

Hello, to update SDK version, please follow these steps:

1. Go to this link: [Install iOS SDK | Amity Docs](https://docs.amity.co/getting-started/installation-and-authentication/install-ios-sdk)
2. Download the latest SDK version.
3. Replace the existing SDK in the UIKit at AmityUIKit/Frameworks/AmitySDK.

---

<div class="post-metadata">

### Author: ![nadol](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@nadol](https://forum.social.plus/u/nadol)
#### Post date: [May 24, 2024, 4:16pm UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/17 "2024-05-24T16:16:24Z")

</div>

@SocialPlus_Support like I mentioned I’m using open source uikit version which is using `SharedFrameworks` to provide `AmitySDK`

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [May 27, 2024, 10:40am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/18 "2024-05-27T10:40:06Z")

</div>

@nadol Let me pass this on to my team to check, and I’ll get back to you.

---

<div class="post-metadata">

### Author: ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)
#### Post date: [June 6, 2024, 11:14am UTC](https://forum.social.plus/t/subchannel-unread-count-doesnt-work-for-community-channels/1290/19 "2024-06-06T11:14:59Z")

</div>

@nadol After consulting with the team, we recommend updating to version 4.0.0 beta 11, as it already includes the updated SDK version. Updating the SDK separately is not advisable due to performance concerns and the potential for further issues.
