设为首页收藏本站

AnyChat技术支持论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
12
返回列表 发新帖
楼主: Crystal

ios 透明通道问题

[复制链接]

4

主题

41

帖子

278

积分

中级会员

Rank: 3Rank: 3

积分
278
发表于 2014-8-18 17:40:25 | 显示全部楼层
本帖最后由 chenxs 于 2014-8-18 17:44 编辑

A 发数据给B时,接收方B才会触发AnyChatTransDataDelegate代理里的方法,而A是不会 触发的。

我是B接收方,叫另外一个人A发文字数据来我B方触发代理方法可以显示到结果。具体代码共享一下,看楼主有没有少了那部分。

注意一点,发送方,设置编码是UTF8,那么接收方也要是UTF8解码,不然接收方不发送方编码不一会出现乱码。

头文件:
#import "AnyChatPlatform.h"
#import "AnyChatDefine.h"
#import "AnyChatErrorCode.h"

@interface ClassName : UIViewController<AnyChatNotifyMessageDelegate,AnyChatTransDataDelegate,NSCoding>

@property (nonatomic, retain) AnyChatPlatform *cxsAnyChatPlatform;
- (void)AnyChatNotifyHandler:(NSNotification*)notify;

实现文件:
- (void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AnyChatNotifyHandler:) name:@"ANYCHATNOTIFY" object:nil];
    [AnyChatPlatform InitSDK:0];

    //登录
    [AnyChatPlatform Connect: GetServerIP : GetServerPort];
    [AnyChatPlatform Login:UserName : Password];

    //设置代理
    cxsAnyChatPlatform = [[AnyChatPlatform alloc] init];
    cxsAnyChatPlatform.notifyMsgDelegate  = self;  //basis Delegate
    cxsAnyChatPlatform.transDataDelegate = self;
}

#pragma mark - AnyChatNotifyMessageDelegate 异步消息事件协议
// 连接服务器消息
- (void) OnAnyChatConnect:(BOOL) bSuccess{}
// 用户登陆消息
- (void) OnAnyChatLogin:(int) dwUserId : (int) dwErrorCode
{
    [AnyChatPlatform EnterRoom:1 :nil];
}
// 用户进入房间消息
- (void) OnAnyChatEnterRoom:(int) dwRoomId : (int) dwErrorCode{}
// 房间在线用户消息
- (void) OnAnyChatOnlineUser:(int) dwUserNum : (int) dwRoomId{}
// 用户进入房间消息
- (void) OnAnyChatUserEnterRoom:(int) dwUserId{}
// 用户退出房间消息
- (void) OnAnyChatUserLeaveRoom:(int) dwUserId{}
// 网络断开消息

- (void) OnAnyChatLinkClose:(int) dwErrorCode{}

#pragma mark - AnyChatTransDataDelegate  数据传输事件协议
// 透明通道回调函数
- (void) OnAnyChatTransBufferCallBack:(int) dwUserid : (NSData*) lpBuf{
   //NSLog(@"发送方的用户ID%i",dwUserid);
    if (lpBuf != nil) {
        NSString *aString = [[NSString alloc] initWithData:lpBuf encoding: NSUTF8StringEncoding];
        NSLog(@"发送的文件内容是%@",aString);        
    }
}
// 透明通dwUserid数
- (void) OnAnyChatTransBufferExCallBack:(int) dwUserid : (NSData*) lpBuf : (int) wParam : (int) lParam : (int) dwTaskId{}
// 文件传输回调函数
- (void) OnAnyChatTransFileCallBack:(int) dwUserid : (NSString*) lpFileName : (NSString*) lpTempFilePath : (int) dwFileLength : (int) wParam : (int) lParam : (int) dwTaskId{}
// SDK Filter 通信数据回调函数

- (void) OnAnyChatSDKFilterDataCallBack:(NSData*) lpBuf{}

//通知中心句柄
- (void)AnyChatNotifyHandler:(NSNotification*)notify
{
    NSDictionary* dict = notify.userInfo;
    [cxsAnyChatPlatform OnRecvAnyChatNotify:dict];
}

回复 支持 反对

使用道具 举报

8

主题

41

帖子

144

积分

注册会员

Rank: 2

积分
144
 楼主| 发表于 2014-9-3 11:43:01 | 显示全部楼层
chenxs 发表于 2014-8-18 17:40
A 发数据给B时,接收方B才会触发AnyChatTransDataDelegate代理里的方法,而A是不会 触发的。

我是B接收 ...

这些只有接收啊,没有发送数据的代码啊,A方代码呢
回复 支持 反对

使用道具 举报

4

主题

41

帖子

278

积分

中级会员

Rank: 3Rank: 3

积分
278
发表于 2014-9-3 12:55:20 | 显示全部楼层
本帖最后由 chenxs 于 2014-9-3 15:55 编辑

您好,在A方登录成功之后,就可以调用以下TransBuffer方法发了。

- (void) OnAnyChatLogin:(int) dwUserId : (int) dwErrorCode
{
        NSString *stext = [[NSString alloc] initWithFormat:@"中文发送"];
        NSData* sData = [stext dataUsingEncoding:NSUTF8StringEncoding];

        [AnyChatPlatform TransBuffer:userID :sData];        //发信息
}




回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|AnyChat ( 粤ICP备13022410号-1 )  

GMT+8, 2024-4-17 05:10 , Processed in 0.112208 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表