說明
公眾號(hào)模塊主要包括公眾號(hào)列表、消息列表、詳情和搜索界面。融云都上訴界面進(jìn)行了封裝,使用公眾號(hào)只需調(diào)用融云自帶的 viewcontroll,包括:
* RCPublicServiceListViewController:公眾號(hào)列表
* RCPublicServiceChatViewController:消息列表
* RCPublicServiceProfileViewController:詳情
* RCPublicServiceSearchViewController:搜索
自定義UI
絕大情況下,我們都需要安裝美工所提供的效果圖來(lái)進(jìn)行開發(fā),但是使用融云的公眾號(hào)自定義UI有著諸多限制。
公眾號(hào)列表
公眾號(hào)列表自定義的方法相對(duì)比較簡(jiǎn)單,提供一個(gè)tableview,數(shù)據(jù)源通過融云的API去獲取。
NSArray *publicServices = [[RCIMClient sharedRCIMClient] getPublicServiceList];
這里所能獲取的是已關(guān)注的公眾號(hào)數(shù)組。
消息列表
最主要的消息列表是沒有辦法提供自定義的。除了導(dǎo)航欄和輸入框,公眾號(hào)消息 cell 無(wú)法和其他自定義消息一樣去定義。
按照正常的融云自定義消息的方式去定義的話
// RCPublicServiceMultiRichContentMessage公眾號(hào)的圖文消息
[self registerClass:[SubscriptionMessageCell class] forMessageClass:[RCPublicServiceMultiRichContentMessage class]]
則會(huì)報(bào)錯(cuò)
-[SubscriptionMessageCell setPublicServiceDelegate:]: unrecognized selector sent to instance 0x7f99e8e39b50
這個(gè) delegate 并沒有開放給我們
融云給出的答復(fù)是:
* 聯(lián)系我們商務(wù)同事索取 IMKit 源碼,直接拿 IMKit 中RCPublicServiceMultiRichContentMessage 對(duì)應(yīng) cell 的源碼進(jìn)行修改
* 詳細(xì)描述您的需求,我們根據(jù)您的需求判斷如何處理
基本等于沒法改…
底部輸入框的隱藏方法
self.chatSessionInputBarControl.hidden = YES;
CGRect rect = self.conversationMessageCollectionView.frame;
rect.size.height = self.view.frame.size.height-kStatusAndNavBarHeight;
self.conversationMessageCollectionView.frame = rect;
自定義消息列表的啟動(dòng)
// ConversationType_APPSERVICE應(yīng)用內(nèi)公眾號(hào)(無(wú)法添加底部菜單欄)
RCPublicServiceProfile *servicePro = [_sortDataSource objectForKey:_indexDataSource[indexPath.section]][indexPath.row];
SubscriptionViewController *vc = [[SubscriptionViewController alloc] init];
vc.conversationType = ConversationType_APPSERVICE;
vc.targetId = servicePro.publicServiceId;
vc.title = servicePro.name;
vc.servicePro = servicePro;
[[AppDelegate sharedAppDelegate] pushViewController:vc];
詳情
獲取公眾號(hào)詳情的 API 有兩種:
從服務(wù)器獲取
- (void)getPublicServiceProfile:(NSString *)targetId
conversationType:(RCConversationType)type
onSuccess:(void (^)(RCPublicServiceProfile *serviceProfile))onSuccess
onError:(void (^)(NSError *error))onError;
從緩存中獲取
- (RCPublicServiceProfile *)getPublicServiceProfile:(RCPublicServiceType)publicServiceType
publicServiceId:(NSString *)publicServiceId;
這兩個(gè)方法都只能獲取已關(guān)注的公眾號(hào),無(wú)法獲取未關(guān)注公眾號(hào)
詳情中的關(guān)注和取消關(guān)注 API 如下:
關(guān)注:
- (void)subscribePublicService:(RCPublicServiceType)publicServiceType
publicServiceId:(NSString *)publicServiceId
success:(void (^)(void))successBlock
error:(void (^)(RCErrorCode status))errorBlock;
如果后臺(tái)設(shè)置的公眾號(hào)是默認(rèn)關(guān)注,是無(wú)法取消的
取消關(guān)注:
- (void)unsubscribePublicService:(RCPublicServiceType)publicServiceType
publicServiceId:(NSString *)publicServiceId
success:(void (^)(void))successBlock
error:(void (^)(RCErrorCode status))errorBlock;
搜索
融云搜索API
可設(shè)置為模糊搜索,搜索出結(jié)果包括關(guān)注和未關(guān)注
- (void)searchPublicServiceByType:(RCPublicServiceType)publicServiceType
searchType:(RCSearchType)searchType
searchKey:(NSString *)searchKey
success:(void (^)(NSArray *accounts))successBlock
error:(void (^)(RCErrorCode status))errorBlock;
如果只需要已關(guān)注公眾號(hào),調(diào)用獲取公眾號(hào)接口,在返回?cái)?shù)組中篩選數(shù)據(jù)