ios - 使用 XMPP 聊天在 iPhone 中传输文件

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

最佳答案

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

关于ios - 使用 XMPP 聊天在 iPhone 中传输文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11576922/

相关文章:

ios - 在 iOS 上获取当前位置

ios - 专注于输入字段和方向变化会扰乱 iOS 6 Safari 上的缩放级别

javascript - 信号 R : How to send a complex object with XmppClient. 发送方法?

ios - 适用于 iOS 的 Robbiehanson xmpp 框架不接收聊天消息

ios - iOS 中的 MUC 使用 robbiehanson XMPP 框架

ios - 无法使用带有电子邮件/密码的 Firebase 简单登录来执行完成 block

ios - 为什么 UIButton 框架被 setTitle : forState: method 重置

python - 如何在本地机器上测试xmpp/jabber?

iphone - 如何在objective-C中实现XMPP协议(protocol)?

iphone - iOS XMPP群聊实现