iosobjective-cejabberdxmppframework

How can I set Resource in XMPP Framework in iOS


I am creating a chat app using ejabberd in iOS & android. The application also have offline push notification. To do this I need to connect to same resource every time I login. In android , I can do this as follows

 XMPPTCPConnectionConfiguration.Builder confBuilder = XMPPTCPConnectionConfiguration.builder()
            .setServiceName(serviceName)
            .setUsernameAndPassword(jidParts[0], password)
            .setConnectTimeout(3000)
            // .setDebuggerEnabled(true)
            .setResource("xxxxx")
            .setSecurityMode(ConnectionConfiguration.SecurityMode.required);

But in IOS , I can't setResource because I don't know how to set this on iOS. the login code is as follows

 - (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;
}

How can I ad resource in above code?


Solution

  • You can set a resource by changing the init method of XMPPJID to

    [xmppStream setMyJID:[XMPPJID jidWithString:myJID resource:resourceId]];
    

    This is an overloaded method in XMPPJID