简体   繁体   中英

How to implement the way to send a friend request in XMPPFramework in iOS?

I have already figured the way to accept a subscription request in XMPPRoster using the following in MainAppDelegate.m :

- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
    {
     NSString *presenceType = [presence type];
     if  ([presenceType isEqualToString:@"subscribe"]) {
       [xmppRoster acceptPresenceSubscriptionRequestFrom:[presence from] andAddToRoster:YES];
   } 

However, I am not able to send a friend request on a button click. The main problem I am facing is that my New Friend add form is in a separate ViewController.m class than MainAppDelegate.m . How do I access the XMPPRoster methods from ViewController.m ? Do I have to redeclare the object for XMPPRoster or can I somehow reuse the object already instantiated in MainAppDelegate.m file?

It should be sufficient to reuse the already existing XMPPRoster object. For that you could write a custom init-method for your ViewController.m, eg

    - initWithRoster:(XMPPRoster *)roster
    {
       self = [super initWithNibName:@"nibName" bundle:nil];
       ...
    } 

and then assign the roster to an instance variable or property of ViewController. It is possible then to access the XMPPRoster object when the view is loading and loaded.

Alternatively you could just add an XMPPRoster property to ViewController and assign the roster object from MainAppDelegate after the view controller is instantiated but before the controller is displayed. Yet I prefer the first solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM