【发布时间】:2014-09-22 21:27:39
【问题描述】:
我正在尝试使用 iOS 上的 XMPPFramework 连接到公共 XMPP 服务器。我在应用加载时设置了连接
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Set up XMPP stream
self.xmppStream = [[XMPPStream alloc] init];
[self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
self.xmppStream.hostName = @"jabber.web.id";
self.xmppStream.hostPort = 5222;
[self connect];
连接中:
- (void)connect {
NSString *username = @"eric1234";
self.password = @"test123";
[self.xmppStream setMyJID:[XMPPJID jidWithString:username]];
NSError *error = nil;
if (![self.xmppStream oldSchoolSecureConnectWithTimeout:XMPPStreamTimeoutNone error:&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];
}
NSLog(@"%hhd", [self.xmppStream isConnected]);
}
然后是我的委托方法:
- (void)xmppStreamDidConnect:(XMPPStream *)sender {
NSError *error = nil;
if (![self.xmppStream authenticateWithPassword:self.password error:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:[NSString stringWithFormat:@"Can't authenticate %@", [error localizedDescription]]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}
[self.xmppStream sendElement:[XMPPPresence presence]];
}
xmppStreamDidConnect 永远不会被调用。我不知道为什么,我已经使用服务器上的桌面 XMPP 客户端在 jabber.web.id 上成功注册了 eric1234。有什么想法吗?
【问题讨论】:
-
我尝试了您的代码,无论我做什么,我似乎都没有收到任何错误。它对我不起作用。
-
这是我遇到的问题,这该死的东西根本不会说话。
标签: ios objective-c xmpp xmppframework