2012-12-29 2 views
1

나는 다음과 같은 코드를 사용 :XMPPFramework - 내 프로필 상태를 변경하려면 어떻게해야합니까? 내 기록 상태를 변경하는

XMPPPresence *presence = [XMPPPresence presenceWithType:@"away"]; 
    [[self xmppStream] sendElement:presence]; 

을하지만 [self xmppStream]의 참조를 받고 있지 않다. 그래서 다음 코드로 변경했습니다 :

XMPPPresence *presence = [XMPPPresence presence]; 
    NSXMLElement *status = [NSXMLElement elementWithName:@"status"]; 
    [status setStringValue:@"away"]; 
    [presence addChild:status]; 
    NSError *error = nil; 

    xmppStream = [[XMPPStream alloc] init]; 
    [xmppStream disconnect]; 
    NSString *myJID = [NSString stringWithFormat:@"%@", appDelegate.jid]; 
    XMPPJID *JID;   
    JID = [XMPPJID jidWithString:myJID]; 
    NSLog(@"%@",JID); 
    [xmppStream setMyJID:JID]; 
    [email protected]"talk.google.com"; 

    [xmppStream connect:&error];   
    [xmppStream sendElement:presence]; 

변경된 상태를 아직받지 못했습니다. 아이디어를 공유하십시오. 미리 감사드립니다.

답변

1

goOnline 방법을 통해 로그인 한 직후 상태를 변경할 수 있습니다. xmppStreamDidAuthenticate 이후에 전화가 걸립니다.

- (void)goOnline 
{ 
    // Initialize XMPPPresence variable 
    XMPPPresence *presence = [XMPPPresence presence]; 

    // Initialize XML element <show/> for specifying your status 
    NSXMLElement *show = [NSXMLElement elementWithName:@"show"]; 

    // Initialize XML element <status/> for describing your status 
    NSXMLElement *status = [NSXMLElement elementWithName:@"status"]; 

    // If you want your user status to be shown as "Available" 
    [show setStringValue:@"chat"]; 
    [status setStringValue:@"Available"]; 

    // If you want your user status to be shown as "Busy" 
    [show setStringValue:@"dnd"]; 
    [status setStringValue:@"Busy"]; 

    // If you want your user status to be shown as "Away" 
    [show setStringValue:@"away"]; 
    [status setStringValue:@"Away"]; 

    // If you want your user status to be shown as "Off-day" 
    [show setStringValue:@"xa"]; 
    [status setStringValue:@"Off-day"]; 

    // Add the XML elements to XMPPPresence 
    [presence addChild:show]; 
    [presence addChild:status]; 

    // Update new presence to server 
    [xmppStream sendElement:presence]; 
} 

자세한 내용과 위 코드에 대한 설명은 Change XMPPPresence to Away/Busy/Invisible을 참조하십시오.

1

위임자가 xmppStreamDidAuthenticate을 청취하여 대기 연결을 보내야 대기 할 때까지 기다려야합니다.

또한 현재 상황을 브로드 캐스트 할 때 JID를 to 또는 from으로 설정하지 않아도됩니다.

+0

그래서 추가 라인을 추가 할 필요가 없다고 말하면 ... – Myaaoonn