【问题标题】:File transfer in iPhone using XMPP chat使用 XMPP 聊天在 iPhone 中传输文件
【发布时间】:2012-07-19 14:05:10
【问题描述】:

我正在使用 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 中使用 turn socket 在聊天应用程序中实现文件传输? 谁能帮我? 提前致谢

【问题讨论】:

标签: ios xmpp xmppframework


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-25
    • 2012-12-12
    • 1970-01-01
    • 2012-12-19
    • 2018-02-17
    相关资源
    最近更新 更多