Delete a channel
To remove one or more channels from the local channel list, use the SDK's channel deletion APIs. The client-side channel list is generated from local messages, so deleting a channel removes the local channel record only.
Delete a single channel
Call delete(completion:) on a channel instance. This method does not delete messages in the channel. After deletion, refresh the UI to hide the channel.
- Swift
- Objective-C
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else {
return
}
channel.delete { isSuccess, error in
if isSuccess {
print("Channel deleted")
} else {
print("Failed to delete: \(error?.localizedDescription ?? "unknown error")")
}
}
NCDirectChannel *channel = [[NCDirectChannel alloc] initWithChannelId:@"targetUserId"];
[channel deleteWithCompletion:^(BOOL isSuccess, NCError * _Nullable error) {
if (isSuccess) {
NSLog(@"Channel deleted");
} else {
NSLog(@"Failed to delete: %@", error);
}
}];
If a new message arrives for a deleted channel, the channel reappears in the list with full message history.
The SDK does not provide a single method to delete both a channel and its messages. To also delete messages, call the message deletion API separately. See Delete messages.
Delete multiple channels by identifier
Call BaseChannel.deleteChannels(identifiers:completion:) with an array of channel identifiers. The recommended maximum is 20 identifiers per request.
- Swift
- Objective-C
import NexconnChatSDK
let identifier1 = ChannelIdentifier(channelType: .direct, channelId: "user1")
let identifier2 = ChannelIdentifier(channelType: .direct, channelId: "user2")
BaseChannel.deleteChannels(identifiers: [identifier1, identifier2]) { error in
if error == nil {
print("Delete succeeded")
}
}
NCChannelIdentifier *identifier1 = [[NCChannelIdentifier alloc] initWithChannelType:NCChannelTypeDirect
channelId:@"user1"];
NCChannelIdentifier *identifier2 = [[NCChannelIdentifier alloc] initWithChannelType:NCChannelTypeDirect
channelId:@"user2"];
[NCBaseChannel deleteChannels:@[identifier1, identifier2]
completion:^(NCError * _Nullable error) {
if (error == nil) {
NSLog(@"Delete succeeded");
}
}];
Delete all channels
The SDK does not provide a one-call method to clear all channels. Query the local channel list first, then delete the returned channel identifiers:
- Swift
- Objective-C
import NexconnChatSDK
let params = ChannelsQueryParams()
params.setChannelTypes([.direct, .group, .system])
params.pageSize = 50
let query = BaseChannel.createChannelsQuery(params: params)
query.loadNextPage { page, error in
guard let channels = page?.data, error == nil, !channels.isEmpty else {
return
}
let identifiers = channels.map {
ChannelIdentifier(channelType: $0.channelType, channelId: $0.channelId)
}
BaseChannel.deleteChannels(identifiers: identifiers) { deleteError in
print(deleteError == nil ? "success" : deleteError!.localizedDescription)
}
}
The current public iOS SDK documents paginated loadNextPage(_:) channel queries in Swift. Verify the generated framework header in your build if you need the Objective-C selector surface for this query type.