このリンクから約 6 か月前に robbiehanson/XMPPFramework をダウンロードしました: https://github.com/robbiehanson/XMPPFramework。「はじめに」セクションに記載されている手順に従いました。エラーは発生しませんでした。以下の手順に従って、アプリケーションで 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];
}
これで、メッセージ/プレゼンスなどを送受信できます。