我大約6個月後從這個鏈接下載了robbiehanson/XMPPFramework:https://github.com/robbiehanson/XMPPFramework。我遵循Getting Started部分中提到的步驟。它沒有拋出任何錯誤。試着按照這些步驟來設置你的應用程序的xmppframework。
在示例應用程序中,我找到了我在啓動應用程序時調用的函數setupStream()
。在這個函數中,我創建一個xmppStream並激活我的應用程序中需要的不同模塊。例如
xmppStream = [[XMPPStream alloc] init];
// Activate xmpp modules after creating them
[xmppReconnect activate:xmppStream];
[xmppRoster activate:xmppStream];
[xmppvCardTempModule activate:xmppStream];
[xmppvCardAvatarModule activate:xmppStream];
[xmppCapabilities activate:xmppStream];
// Add ourself as a delegate to anything we may be interested in
[xmppStream addDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
[xmppStream setHostName:XMPPHOST];
[xmppStream setHostPort:5222];
// You may need to alter these settings depending on the server you're connecting to
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;
設置流之後,你需要做這樣的鑑定:
- (BOOL)connect:(NSString *)myJID //username registered with server
{
if (![xmppStream isDisconnected]) {
return YES;
}
if (myJID == nil) {
return NO;
}
[xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
NSError *error = nil;
if (![xmppStream connect:&error])
{
if(DEBUG)
{
NSLog(@"ERROR: Not connected to XMPP Server");
}
DDLogError(@"Error connecting: %@", error);
return NO;
}
return YES;
}
此功能將被框架調用,通過這裏的密碼:
- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
if(sender == xmppStream)
{
//DDLogVerbose(@"In xmppStream: %@: %@", THIS_FILE, THIS_METHOD);
isXmppConnected = YES;
NSError *error = nil;
if (![[self xmppStream] authenticateWithPassword:password error:&error])
{
DDLogError(@"Error authenticating: %@", error);
}
}
}
現在如果用戶通過認證,此功能將被稱爲:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
if(sender == xmppStream)
{
[self goOnline];
}
}
goOnline將發送用戶的存在服務器:
- (void)goOnline
{
XMPPPresence *presence = [XMPPPresence presence]; // type="available" is implicit
[xmppStream sendElement:presence];
}
現在,您可以發送/接收消息/存在等
2幾年前,我下載了它的基本版本。不是更新的,並且完成了一個POC推送通知。在那裏我配置了gtalk,後來poc被納入雷達。現在我沒有任何源代碼可以幫助你,但我想幫助你... – 2013-02-28 09:28:38
好的..謝謝你@AnoopVaidya – Babul 2013-02-28 09:29:51
@BabulI已經將XMPP框架及其所有依賴項添加到我的iPhone聊天應用程序中,並且它沒有給出任何錯誤(已成功構建)。現在你可以幫我,現在我需要在我的應用程序中添加XMPP框架後做些什麼..?謝謝 – 2014-01-23 07:55:41