Accept interlocutor request in xmpp client iphone

I am developing xmpp client for iphone. I can send and receive messages. I want to accept the interlocutor's request automatically without prompting the user. In which function will I receive the request. Please give me any hints.

Thanks in advance.

+3


source to share


3 answers


Ok, I have a great answer for you!

Here is the code:

- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence {

    // a buddy went offline/online

    NSString *presenceType = [presence type];            // online/offline
    NSString *myUsername = [[sender myJID] user];
    NSString *presenceFromUser = [[presence from] user];

    if (![presenceFromUser isEqualToString:myUsername]) {

        if ([presenceType isEqualToString:@"available"]) {

            [_chatDelegate newBuddyOnline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, kHostName]];
               NSLog(@"presence user is %@",presenceFromUser);

        } 

        else if  ([presenceType isEqualToString:@"unavailable"]) {

            [_chatDelegate buddyWentOffline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, kHostName]];
            NSLog(@"presence user is invisible %@",presenceFromUser);

        }
        else if  ([presenceType isEqualToString:@"subscribe"]) {

            [_chatDelegate newBuddyOnline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, kHostName]];
                        NSLog(@"presence user wants to subscribe %@",presenceFromUser);

        }

    }
}

      

I have provided you with the complete DidReceivePresence method code for your better understanding.



Now let me explain the code to you. If you notice that in the else if clause I am comparing the value (item) we get. So when I get a string like "Subscribe" (when a user sends a request to a friend), you just need to add that particular user to the contact list in the table.

You can get the username from "presenceFromUser".

If you need more understanding then email me at blueobaid@gmail.com because I don't get any alerts when you reply to my answer, although I will come back and reply here to help others too! and I will put a tutorial on http://Czartechnogeeks.com/iSolutions soon

I'm glad I was able to share with the user what is valuable to the user using stackoverflow after helping me a lot.

+7


source


U will not receive a request in a separate function. Whenever a buddy comes online or makes a request, the didReceivePresence delegate function is called. if you get presence type = subscription it will be buddyrequest. Hope this helps you.



+4


source


You will receive the subscription in the didReceivePresence function .

To accept a subscription, you can use this code:

  NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
  [presence addAttributeWithName:@"type" stringValue:@"subscribed"];
  [presence addAttributeWithName:@"to" stringValue:[presence fromStr]];
  [presence addAttributeWithName:@"from" stringValue:@"you@host"];
  [[self xmppStream] sendElement:presence];

      

Let this help :)

+2


source







All Articles