【问题标题】:XMPPFramework not sending presenceXMPPFramework 不发送存在
【发布时间】:2012-06-15 06:29:19
【问题描述】:

我正在为 iPhone 开发一个应用程序,其中一个功能是使用 XMPPFramework 的即时消息系统。到目前为止,我正在使用 Google Talk 对其进行测试。委托与管理用户界面的类相同。所以,我得到了这个代码:

在 viewDidLoad 中:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupStream];
}

setupStream 方法:

- (void) setupStream
{
    NSLog(@"Inside setupStream");
    xmppStream = [[XMPPStream alloc] init];
    [xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [self connect];
}

连接方法:

- (BOOL) connect
{
    NSLog(@"Inside connect method");


    General *general = [General sharedManager];//this is a singleton to manage settings for every user
    NSString *chatid;
    NSString *chatpass;

    //chatid=[general user];
    chatid=@"somegmailaccount@gmail.com";
    xmppStream.myJID=[XMPPJID jidWithString:chatid];

    if (![xmppStream isDisconnected]) {
        return YES;
    }

    NSError *error = nil;
    if (![xmppStream connect:&error])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
            message:[NSString stringWithFormat:@"Can't connect to server %@", [error localizedDescription]]
            delegate:nil
            cancelButtonTitle:@"Ok"
            otherButtonTitles:nil];
        [alertView show];

        return NO;
    }

    return YES;
}

在 xmppStreamDidConnect 方法中:

- (void) xmppStreamDidConnect:(XMPPStream *)sender
{
    [xmppStream authenticateWithPassword:@"password" error:NULL];
    [self goOnline];
}

还有goOnline方法:

- (void) goOnline
{
    XMPPPresence *presence = [XMPPPresence presence];
    [[self xmppStream] sendElement:presence];
    NSLog(@"Presence sent");
}

这样,就不会发送出席信息。我有另一个谷歌帐户,我尝试进行测试(例如,testing@gmail.com),在这个帐户中没有看到 somegmailaccount.gmail.com 的存在。两个帐户相互关联并且相互了解,因为我使用相同的帐户来开发 Android 应用。

知道我做错了什么吗?任何帮助表示赞赏。

非常感谢。

【问题讨论】:

    标签: iphone xcode xmppframework


    【解决方案1】:

    我找到了!出席信息不是通过这种方式发送的:

    XMPPPresence *presence = [XMPPPresence presence];
    [[self xmppStream] sendElement:presence];
    

    Insted,我是这样做的:

    NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
    [xmppStream sendElement:presence];
    

    这样,发送状态没有任何问题:)

    【讨论】:

    【解决方案2】:

    使用此代码,我实现方法 xmppStreamDidAuthenticate:(XMPPStream *)sender 并且程序确实在没有我的代码调用的情况下进入该方法。但如果我把

    [xmppStream setHostName:@"talk.google.com"];
    [xmppStream setHostPort:5222];
    

    ...在connect方法中,程序不要进入那个方法,也不要进入xmppStreamDidConnect。

    我生气了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 2012-10-26
      • 2014-09-23
      • 1970-01-01
      • 2014-04-27
      相关资源
      最近更新 更多