Question

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?

Was it helpful?

Solution

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

    - 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top