【发布时间】:2019-03-07 06:03:55
【问题描述】:
我正在使用 iOS 和 android 中的 ejabberd 创建一个聊天应用程序。该应用程序还具有离线推送通知。为此,我每次登录时都需要连接到相同的资源。在 android 中,我可以这样做
XMPPTCPConnectionConfiguration.Builder confBuilder = XMPPTCPConnectionConfiguration.builder()
.setServiceName(serviceName)
.setUsernameAndPassword(jidParts[0], password)
.setConnectTimeout(3000)
// .setDebuggerEnabled(true)
.setResource("xxxxx")
.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
但在 IOS 中,我不能 setResource 因为我不知道如何在 iOS 上设置它。
登录代码如下
- (BOOL)connect:(NSString *)myJID withPassword:(NSString *)myPassword auth:(AuthMethod)auth hostname:(NSString *)hostname port:(int)port
{
if (![xmppStream isDisconnected]) {
[self disconnect];
}
if (myJID == nil || myPassword == nil) {
return NO;
}
NSLog(@"Connect using JID %@", myJID);
[xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
username = myJID;
password = myPassword;
authMethod = auth;
xmppStream.hostName = (hostname ? hostname : [username componentsSeparatedByString:@"@"][1]);
if(port){
xmppStream.hostPort = port;
}
NSError *error = nil;
if (port == 5223) {
self.xmppReconnect.usesOldSchoolSecureConnect = YES;
if (![xmppStream oldSchoolSecureConnectWithTimeout:30 error:&error])
{
DDLogError(@"Error connecting: %@", error);
if (self.delegate){
[self.delegate onLoginError:error];
}
return NO;
}
} else {
if (![xmppStream connectWithTimeout:30 error:&error])
{
DDLogError(@"Error connecting: %@", error);
if (self.delegate){
[self.delegate onLoginError:error];
}
return NO;
}
}
return YES;
}
如何在上面的代码中广告资源?
【问题讨论】:
-
分配 JIDString 后,资源和域将由 XMPP 框架处理。
-
@SachinVas 但是当我连接到 xmpp 服务器时,我想分配给相同的资源。这也是在 XMPP 框架中处理的吗?
-
为什么你需要相同的资源来使用推送通知?例如,对于 Tigase XMPP 服务器的 Tigase Push 组件,没有这样的限制(视频docs.tigase.net/tigase-push/1.0.0/…); iOS 的 Tigase Swift 库 (docs.tigase.net/tigase-swift/snapshot/Tigase_Swift_Guide/html) 还支持设置资源
-
可以分配不同的资源,看重载的init方法就行了。
标签: ios objective-c ejabberd xmppframework