Commit 5a02b24ce99067b33f61f79965f92407908cd200
1 parent
57b55bff
添加聊天室初始化方法
Showing
2 changed files
with
123 additions
and
40 deletions
LiveVideoCloud/LiveVideoCloud/AppDelegate/AppDelegate.m
| ... | ... | @@ -21,6 +21,14 @@ |
| 21 | 21 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; |
| 22 | 22 | self.window.rootViewController = [[ZXTabBarController alloc] init]; |
| 23 | 23 | [self.window makeKeyAndVisible]; |
| 24 | + | |
| 25 | + [[CNLiveChatManager sharedCNLiveChatManager] initWithAppKey:AppKey appId:AppId]; | |
| 26 | + [[CNLiveChatManager sharedCNLiveChatManager] connectServerSuccess:^{ | |
| 27 | + | |
| 28 | + } error:^(CNLiveChatConnectErrorCode errors) { | |
| 29 | + | |
| 30 | + }]; | |
| 31 | + | |
| 24 | 32 | return YES; |
| 25 | 33 | } |
| 26 | 34 | ... | ... |
LiveVideoCloud/LiveVideoCloud/Classes/Sections/InteractionSections/LiveBaseView.m
| ... | ... | @@ -26,22 +26,23 @@ typedef NS_ENUM(NSInteger, PopType) {//弹窗类型 |
| 26 | 26 | PopTypePriMessage //私信弹窗 |
| 27 | 27 | }; |
| 28 | 28 | |
| 29 | -@interface LiveBaseView ()<bottomBtnDeledate,PresentViewDelegate,UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,userClickDelegate> | |
| 30 | - | |
| 31 | -@property (nonatomic ,strong ) UIScrollView * _Nullable scrollView; | |
| 32 | -@property (nonatomic ,strong ,readwrite) UIView * _Nullable animationBaseView;//展示层View | |
| 33 | -@property (nonatomic ,strong ) BottomToolView* _Nullable bottomToolView; | |
| 34 | -@property (nonatomic ,strong ) UIButton * _Nullable closeBtn; | |
| 35 | -@property (nonatomic ,strong ) UIView * _Nullable giftPopView; | |
| 36 | -@property (nonatomic ,strong ,readwrite) PresentView * _Nullable presentView;//连击View | |
| 29 | +@interface LiveBaseView ()<bottomBtnDeledate,PresentViewDelegate,UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,userClickDelegate,CNLiveChatManagerDelegate> | |
| 30 | + | |
| 31 | +@property (nonatomic ,strong ) UIScrollView * _Nullable scrollView; | |
| 32 | +@property (nonatomic ,strong ,readwrite) UIView * _Nullable animationBaseView;//展示层View | |
| 33 | +@property (nonatomic ,strong ) BottomToolView* _Nullable bottomToolView; | |
| 34 | +@property (nonatomic ,strong ) UIButton * _Nullable closeBtn; | |
| 35 | +@property (nonatomic ,strong ) GiftListView * _Nullable giftListView; | |
| 36 | +@property (nonatomic ,weak ) UIView * _Nullable giftPopView; | |
| 37 | +@property (nonatomic ,strong ,readwrite) PresentView * _Nullable presentView;//连击View | |
| 37 | 38 | @property (nonatomic ,assign ) PopType popType; |
| 38 | -@property (nonatomic ,strong) UITableView * _Nullable chatTableView; | |
| 39 | -@property (nonatomic ,strong) NSMutableArray * _Nullable chatMsgArray;//聊天消息数组 | |
| 40 | -@property (nonatomic ,strong) TopToolView * _Nullable topToolsView; | |
| 41 | -@property (nonatomic ,strong) UIView * _Nullable commentsView; | |
| 42 | -@property (nonatomic ,strong) UITextField * _Nullable commentText; | |
| 43 | -@property (nonatomic ,assign) CGFloat offsetHeight; | |
| 44 | -@property (nonatomic ,strong) UISwitch * _Nullable barrageSwitch; | |
| 39 | +@property (nonatomic ,strong ) UITableView * _Nullable chatTableView; | |
| 40 | +@property (nonatomic ,strong ) NSMutableArray * _Nullable chatMsgArray;//聊天消息数组 | |
| 41 | +@property (nonatomic ,strong ) TopToolView * _Nullable topToolsView; | |
| 42 | +@property (nonatomic ,strong ) UIView * _Nullable commentsView; | |
| 43 | +@property (nonatomic ,strong ) UITextField * _Nullable commentText; | |
| 44 | +@property (nonatomic ,assign ) CGFloat offsetHeight; | |
| 45 | +@property (nonatomic ,strong ) UISwitch * _Nullable barrageSwitch; | |
| 45 | 46 | |
| 46 | 47 | @end |
| 47 | 48 | |
| ... | ... | @@ -66,6 +67,15 @@ typedef NS_ENUM(NSInteger, PopType) {//弹窗类型 |
| 66 | 67 | [self.animationBaseView addSubview:self.topToolsView]; |
| 67 | 68 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; |
| 68 | 69 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil]; |
| 70 | + | |
| 71 | + [CNLiveChatManager sharedCNLiveChatManager].delegate = self; | |
| 72 | + [[CNLiveChatManager sharedCNLiveChatManager] joinChatRoom:@"123" messageCount:50 success:^(NSString *targetId) { | |
| 73 | + NSLog(@"success"); | |
| 74 | + } error:^(CNLiveChatErrorCode errors, NSString *targetId) { | |
| 75 | + NSLog(@"error"); | |
| 76 | + }]; | |
| 77 | + | |
| 78 | + [CNLiveChatManager sharedCNLiveChatManager].currentUserInfo.portraitUri = @"http://b.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=f0c5c08030d3d539c16807c70fb7c566/8ad4b31c8701a18bbef9f231982f07082838feba.jpg"; | |
| 69 | 79 | } |
| 70 | 80 | return self; |
| 71 | 81 | } |
| ... | ... | @@ -89,18 +99,6 @@ typedef NS_ENUM(NSInteger, PopType) {//弹窗类型 |
| 89 | 99 | self.bottomToolView.hidden = NO; |
| 90 | 100 | } |
| 91 | 101 | |
| 92 | -#pragma mark - UITextFieldDelegate | |
| 93 | -- (BOOL)textFieldShouldReturn:(UITextField *)textField | |
| 94 | -{ | |
| 95 | - if (![textField.text isEqualToString:@""]) { | |
| 96 | - //send message | |
| 97 | - NSLog(@"send message"); | |
| 98 | - textField.text = @""; | |
| 99 | - } | |
| 100 | - [textField resignFirstResponder]; | |
| 101 | - return YES; | |
| 102 | -} | |
| 103 | - | |
| 104 | 102 | - (void)createCommentsView { |
| 105 | 103 | if (!_commentsView) { |
| 106 | 104 | |
| ... | ... | @@ -147,6 +145,23 @@ typedef NS_ENUM(NSInteger, PopType) {//弹窗类型 |
| 147 | 145 | [_commentText becomeFirstResponder];//再次让textView成为第一响应者 |
| 148 | 146 | } |
| 149 | 147 | |
| 148 | +#pragma mark - UITextFieldDelegate | |
| 149 | +- (BOOL)textFieldShouldReturn:(UITextField *)textField | |
| 150 | +{ | |
| 151 | + if (![textField.text isEqualToString:@""]) { | |
| 152 | + //send message | |
| 153 | + NSLog(@"send message"); | |
| 154 | + [[CNLiveChatManager sharedCNLiveChatManager] sendMessage:textField.text type:CNLive_ConversationType_CHATROOM targetId:@"123" success:^(CNLiveChatMessage *message) { | |
| 155 | + NSLog(@"msgid:%@,tagid:%@,content:%@",message.messageId,message.targetId,message.messageContent); | |
| 156 | + } error:^(CNLiveChatErrorCode errors, NSString *messageId, NSString *targetId) { | |
| 157 | + NSLog(@"%@",messageId); | |
| 158 | + }]; | |
| 159 | + textField.text = @""; | |
| 160 | + } | |
| 161 | + [textField resignFirstResponder]; | |
| 162 | + return YES; | |
| 163 | +} | |
| 164 | + | |
| 150 | 165 | #pragma mark - bottomBtnActionDelegate |
| 151 | 166 | - (void)bottomActionWithType:(BtnClickType)btnType button:(UIButton *)button |
| 152 | 167 | { |
| ... | ... | @@ -169,16 +184,9 @@ typedef NS_ENUM(NSInteger, PopType) {//弹窗类型 |
| 169 | 184 | self.popType = PopTypeGift; |
| 170 | 185 | [[LVCAnimationManager shareManager] suspend]; |
| 171 | 186 | [self hiddenView:YES]; |
| 172 | - GiftListView *giftListView = [[GiftListView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 250, SCREEN_WIDTH, 250) liveBaseView:self]; | |
| 173 | - [self addSubview:giftListView]; | |
| 174 | - self.giftPopView = giftListView; | |
| 175 | - | |
| 176 | - UIImageView *giftBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, giftListView.width, giftListView.height)]; | |
| 177 | - giftBg.image = [UIImage imageNamed:@"背景400x300"]; | |
| 178 | - giftBg.centerX = giftListView.width * 0.5; | |
| 179 | - giftBg.centerY = giftListView.height * 0.5; | |
| 180 | - giftBg.alpha = 0.4; | |
| 181 | - [giftListView addSubview:giftBg]; | |
| 187 | + [self addSubview:self.giftListView]; | |
| 188 | + self.giftListView.frame = CGRectMake(0, SCREEN_HEIGHT - 250, SCREEN_WIDTH, 250); | |
| 189 | + self.giftPopView = _giftListView; | |
| 182 | 190 | } |
| 183 | 191 | break; |
| 184 | 192 | default: |
| ... | ... | @@ -207,7 +215,6 @@ typedef NS_ENUM(NSInteger, PopType) {//弹窗类型 |
| 207 | 215 | [self hiddenView:NO]; |
| 208 | 216 | [[LVCAnimationManager shareManager] resume]; |
| 209 | 217 | } completion:^(BOOL finished) { |
| 210 | - [self.giftPopView removeFromSuperview]; | |
| 211 | 218 | }]; |
| 212 | 219 | } |
| 213 | 220 | break; |
| ... | ... | @@ -228,7 +235,7 @@ typedef NS_ENUM(NSInteger, PopType) {//弹窗类型 |
| 228 | 235 | } |
| 229 | 236 | |
| 230 | 237 | |
| 231 | -#pragma mark - buttonClick | |
| 238 | +#pragma mark - buttonClick触摸屏幕关闭方法 | |
| 232 | 239 | - (void)tapGestureClick:(UITapGestureRecognizer *)gesture |
| 233 | 240 | { |
| 234 | 241 | [[LVCAnimationManager shareManager] bubblingWithCenterPoint:CGPointMake(SCREEN_WIDTH - 50, SCREEN_HEIGHT - 50) toView:self.animationBaseView]; |
| ... | ... | @@ -245,12 +252,64 @@ typedef NS_ENUM(NSInteger, PopType) {//弹窗类型 |
| 245 | 252 | [self textFieldShouldReturn:self.commentText]; |
| 246 | 253 | } |
| 247 | 254 | |
| 248 | -#pragma mark - userDetailDelegate | |
| 255 | +#pragma mark - userDetailDelegate聊天室列表个人信息 | |
| 249 | 256 | - (void)userClickWithModel:(chatMsgModel *)model |
| 250 | 257 | { |
| 251 | 258 | NSLog(@"点击人:%@",model.name); |
| 252 | 259 | } |
| 253 | 260 | |
| 261 | +#pragma mark - CNLiveChatManagerDelegate | |
| 262 | +/** | |
| 263 | + 连接状态的的监听器 | |
| 264 | + | |
| 265 | + @param status 网络连接状态码 | |
| 266 | + */ | |
| 267 | +- (void)onConnectionStatusChanged:(CNLiveConnectionStatus)status | |
| 268 | +{ | |
| 269 | + NSLog(@"onConnectionStatusChanged"); | |
| 270 | +} | |
| 271 | + | |
| 272 | +/** | |
| 273 | + 加入聊天室成功的监听 | |
| 274 | + @param chatroomId 聊天室ID | |
| 275 | + */ | |
| 276 | +- (void)onChatRoomJoined:(NSString *)chatroomId | |
| 277 | +{ | |
| 278 | + NSLog(@"onChatRoomJoined"); | |
| 279 | +} | |
| 280 | + | |
| 281 | +/*! | |
| 282 | + 加入聊天室失败的监听 | |
| 283 | + | |
| 284 | + @param chatroomId 聊天室ID | |
| 285 | + @param errorCode 加入失败的错误码 | |
| 286 | + | |
| 287 | + @discussion 如果错误码是CNLive_KICKED_FROM_CHATROOM或CNLive_CHATROOM_NOT_EXIST,则不会自动重新加入聊天室,App需要按照自己的逻辑处理。 | |
| 288 | + */ | |
| 289 | +- (void)onChatRoomJoinFailed:(NSString *)chatroomId | |
| 290 | + errorCode:(CNLiveChatErrorCode)errorCode | |
| 291 | +{ | |
| 292 | + NSLog(@"onChatRoomJoinFailed"); | |
| 293 | +} | |
| 294 | + | |
| 295 | +/** | |
| 296 | + 接收消息监听 | |
| 297 | + | |
| 298 | + @param message 消息实体类型对象(包括消息内容,消息ID,会话类型,目标ID,发送者的用户信息) | |
| 299 | + */ | |
| 300 | +- (void)onReceived:(CNLiveChatMessage *)message | |
| 301 | +{ | |
| 302 | + NSLog(@"onReceived msg:%@",message.messageContent); | |
| 303 | +} | |
| 304 | + | |
| 305 | +/** | |
| 306 | + 当前用户在其他设备上登录,此设备被踢下线。 | |
| 307 | + */ | |
| 308 | +- (void)kickedByAnotherDevice | |
| 309 | +{ | |
| 310 | + NSLog(@"kickedByAnotherDevice"); | |
| 311 | +} | |
| 312 | + | |
| 254 | 313 | #pragma mark - 聊天消息列表 |
| 255 | 314 | #pragma mark - UITableViewDataSource |
| 256 | 315 | |
| ... | ... | @@ -428,6 +487,22 @@ typedef NS_ENUM(NSInteger, PopType) {//弹窗类型 |
| 428 | 487 | return _closeBtn; |
| 429 | 488 | } |
| 430 | 489 | |
| 490 | +- (GiftListView *)giftListView | |
| 491 | +{ | |
| 492 | + if (!_giftListView) | |
| 493 | + { | |
| 494 | + _giftListView = [[GiftListView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 250, SCREEN_WIDTH, 250) liveBaseView:self]; | |
| 495 | + | |
| 496 | + UIImageView *giftBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _giftListView.width, _giftListView.height)]; | |
| 497 | + giftBg.image = [UIImage imageNamed:@"背景400x300"]; | |
| 498 | + giftBg.centerX = _giftListView.width * 0.5; | |
| 499 | + giftBg.centerY = _giftListView.height * 0.5; | |
| 500 | + giftBg.alpha = 0.4; | |
| 501 | + [_giftListView addSubview:giftBg]; | |
| 502 | + } | |
| 503 | + return _giftListView; | |
| 504 | +} | |
| 505 | + | |
| 431 | 506 | /* |
| 432 | 507 | // Only override drawRect: if you perform custom drawing. |
| 433 | 508 | // An empty implementation adversely affects performance during animation. | ... | ... |