Delete a channel
Deleting a channel removes the local channel record from the channel list. This does not delete the messages within the channel — only the channel entry is removed.
Delete a single channel
Call delete(completion:) on a channel instance:
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.delete { success, error in
if success {
print("Channel deleted.")
} else {
print("Failed: \(error?.localizedDescription ?? "unknown error")")
}
}
Objective C
NCDirectChannel *channel = [[NCDirectChannel alloc] initWithChannelId:@"targetUserId"];
[channel deleteWithCompletion:^(BOOL success, NCError *error) {
if (success) {
NSLog(@"Channel deleted.");
} else {
NSLog(@"Failed: %@", error);
}
}];
Delete multiple channels
Call the class method deleteChannels(identifiers:completion:):
- Swift
- Objective-C
swift
import NexconnChatSDK
let id1 = ChannelIdentifier(channelType: .direct, channelId: "user1")
let id2 = ChannelIdentifier(channelType: .group, channelId: "groupId")
BaseChannel.deleteChannels(identifiers: [id1, id2]) { error in
if error == nil {
print("Channels deleted.")
}
}
Objective C
NCChannelIdentifier *id1 = [[NCChannelIdentifier alloc] initWithChannelType:NCChannelTypeDirect
channelId:@"user1"];
NCChannelIdentifier *id2 = [[NCChannelIdentifier alloc] initWithChannelType:NCChannelTypeGroup
channelId:@"groupId"];
[NCDirectChannel deleteChannels:@[id1, id2]
completion:^(NCError *error) {
if (error == nil) {
NSLog(@"Channels deleted.");
}
}];
Alternatively, build an identifiers array and pass it to deleteChannels:completion::
- Swift
- Objective-C
swift
import NexconnChatSDK
let id1 = ChannelIdentifier(channelType: .direct, channelId: "user1")
let id2 = ChannelIdentifier(channelType: .direct, channelId: "user2")
BaseChannel.deleteChannels(identifiers: [id1, id2]) { error in
if error == nil {
print("Channels deleted.")
}
}
Objective C
NCChannelIdentifier *id1 = [[NCChannelIdentifier alloc] initWithChannelType:NCChannelTypeDirect
channelId:@"user1"];
NCChannelIdentifier *id2 = [[NCChannelIdentifier alloc] initWithChannelType:NCChannelTypeDirect
channelId:@"user2"];
[NCBaseChannel deleteChannels:@[id1, id2]
completion:^(NCError * _Nullable error) {
if (error == nil) {
NSLog(@"Channels deleted.");
}
}];