使用XMPP聊天在iPhone中进行文件传输

时间:2012-07-20 09:48:01

标签: ios xmpp xmppframework

我正在使用XMPP框架开发聊天应用程序。 我可以发送和接收聊天消息,我想传输一个文件。

我使用了TURNSocket,但它没有用。

我的代码:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSMutableArray *turnSockets=[NSMutableArray alloc] init];
    }
    return self;
}

- (void)viewDidLoad
{
    XMPPJID *jid = [XMPPJID jidWithString:@"venkat.varra@gmail.com/gmail.9D2001A1"];
    TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:jid];
   [turnSockets addObject:turnSocket];
   [turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
}

- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket 
{
    NSData *dataF = [[NSData alloc] initWithContentsOfFile:
    [[NSBundle mainBundle] pathForResource:@"orange" ofType:@"png"]];

    [socket writeData:dataF withTimeout:60.0f tag:0];
}

- (void)turnSocketDidFail:(TURNSocket *)sender 
{
    NSLog(@"TURN Connection failed!");
    [turnSockets removeObject:sender];          
}

当我运行这个程序时,它总是调用turnsocketDidFail方法。

如何在iPhone中使用转换套接字在聊天应用程序中实现文件传输? 谁能帮我? 提前致谢

1 个答案:

答案 0 :(得分:0)

如果要发送文件,只需使用Web服务将该文件上传到服务器,上传完成后,将上传的文件URL发送给其他用户。 该用户现在可以轻松地从该特定URL下载该文件。

相关问题