WuKongIM iOS SDK channel management functionality, including channel information retrieval, updates and monitoring
The channel manager is responsible for CRUD operations on channel information data. Through channel management, you can implement user/group nicknames, user/group avatars, user/group pinning, user/group do not disturb, and other features.
Personal channels and group channels are collectively called channels. Personal information and group information are collectively called channel information.
This documentation only covers core methods. For more details, check the [WKSDK shared].channelManager interface in the code.
Get channel information from the client’s local storage. If not available locally, call fetchChannelInfo to trigger the data source to request from the server.When fetchChannelInfo is called and channel information data is obtained, it will trigger data monitoring. In the listener, refresh the UI again, and then [[WKSDK shared].channelManager getChannelInfo:channel] will be able to get the channel information data.
Trigger timing: Triggered when calling [[WKSDK shared].channelManager fetchChannelInfo]Channel information data source, needs to implement logic to request channel information from server:
Copy
// channel Channel// callback Should call this callback when getting data from server (Note: callback must be called regardless of success or failure)[[WKSDK shared] setChannelInfoUpdate:^WKTaskOperator * (WKChannel * _Nonnull channel, WKChannelInfoCallback _Nonnull callback) { // Implement your server API call here // Example: [YourAPIManager getChannelInfo:channel.channelId channelType:channel.channelType success:^(WKChannelInfo *channelInfo) { callback(channelInfo, nil); } failure:^(NSError *error) { callback(nil, error); }]; return nil; // Return task operator if needed for cancellation}];
@interface WKChannelInfo : NSObject<NSCopying>// Channel@property(nonatomic,strong) WKChannel *channel;/** Channel name */@property(nonatomic,copy) NSString *name;/** Channel logo/avatar */@property(nonatomic,copy) NSString *logo;/** Whether pinned */@property(nonatomic,assign) BOOL stick;/** Whether muted (do not disturb) */@property(nonatomic,assign) BOOL mute;/// Whether all members are muted@property(nonatomic,assign) BOOL forbidden;/** Whether followed 0.Not followed (stranger) 1.Followed (friend) */@property(nonatomic,assign) WKChannelInfoFollow follow;/** Extension field, custom channel business properties can be added to extension fields */@property(nonatomic,strong) NSMutableDictionary<WKChannelExtraKey,id> *extra;/** Channel status (online/offline for personal channels) */@property(nonatomic,assign) WKChannelStatus status;/** Member count (for group channels) */@property(nonatomic,assign) NSInteger memberCount;/** Channel description */@property(nonatomic,copy) NSString *channelDesc;@end
// Check local cache first, then fetch if needed- (void)loadChannelInfo:(WKChannel *)channel completion:(void(^)(WKChannelInfo *channelInfo))completion { WKChannelInfo *cachedInfo = [[WKSDK shared].channelManager getChannelInfo:channel]; if (cachedInfo) { completion(cachedInfo); } else { // Set up one-time listener for this specific channel __weak typeof(self) weakSelf = self; [[WKSDK shared].channelManager addDelegate:weakSelf]; // Fetch from server [[WKSDK shared].channelManager fetchChannelInfo:channel]; }}// In delegate method-(void) channelInfoUpdate:(WKChannelInfo*)channelInfo oldChannelInfo:(WKChannelInfo* __nullable)oldChannelInfo { // Handle the update and remove delegate if needed // completion(channelInfo);}