1

I am developing an app like RSS Feeds. I want users to get feeds without calling any web service. I read out some documents and got a solution of using XMPP where XMPPPubsub gives us that functionality to send an event notification to all subscribers.

In XMPPPubsub Owner creates a node and other users who want to get event notification subscribes to that node.

  1. Set up XMPPPubsub

    XMPPJID *serviceJID =[XMPPJID jidWithString:[NSString stringWithFormat:@"pubsub.%@",HOST_NAME]];
    _xmppPubSub = [[XMPPPubSub alloc]initWithServiceJID:serviceJID     dispatchQueue:dispatch_get_main_queue()];
    [_xmppPubSub addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [_xmppPubSub activate:_xmppStream];
    
  2. Creation of Node

    - (void)createNodeWithName:(NSString*)nodeName withCompletionHandler:(CreateNodeCompletionHandler)completionBlock{
    
       _createNodeCompletionHandler = completionBlock;
    
       [_xmppPubSub createNode:nodeName withOptions:@{@"pubsub#title":nodeName,@"pubsub#deliver_notifications":@"1",@"pubsub#deliver_payloads":@"0",@"pubsub#persist_items":@"1",@"pubsub#notify_sub":@"1",@"pubsub#subscribe":@"1",@"pubsub#send_last_published_item":@"When a new subscription is processed and whenever a subscriber comes online",@"pubsub#access_model":@"open",@"pubsub#presence_based_delivery":@"1",@"pubsub#publish_model":@"open"}];
    }
    
  3. User who wants to have events must subscribe to node

    - (void)subScribeToNode:(NSString*)nodeName withCompletionHandler:(SubscribeNodeCompletionHandler)completionBlock{
    
      _subscribeNodeCompletionHandler = completionBlock;
      [_xmppPubSub subscribeToNode:nodeName withJID:_xmppStream.myJID options: @{ @"pubsub#deliver"      : @(YES),
                                                                    @"pubsub#digest"       : @(YES),
                                                                     @"pubsub#include_body" : @(YES),
                                                                     @"pubsub#show-values"  : @[ @"chat", @"online", @"away" ] }];
     }
    
  4. Publish the event to node

    - (void)sendMessage:(NSString*)message ToNode:(NSString*)node{
    NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
    [body setStringValue:message];
    
    NSXMLElement *messageBody = [NSXMLElement elementWithName:@"message"];
    [messageBody setXmlns:@"jabber:client"];
    [messageBody addChild:body];
    [_xmppPubSub publishToNode:node entry:messageBody withItemID:nil options:@{@"pubsub#access_model":@"open"}];
    }
    

All is working well Users are able to subscribe to a node. We are able to create the Node. When we get our subscriber nodes, it also returns all the nodes. The events that we published are also there in Database and if I retrieve events by code it also returns all of them.

But the issue is the subscribers are not able to get its notification in didReceiveMessage so subscribers are not getting notified of events.

No logs in below functions

    - (void)xmppPubSub:(XMPPPubSub *)sender didReceiveMessage:(XMPPMessage *)message{
  NSLog(@" -----We Just Received message wooo hooo whow owowhwo -----");
}
    - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq{
    return YES;
}

Please guide me through this what I am doing wrong in it.

Thanks in Advance.

Hemang
  • 26,840
  • 19
  • 119
  • 186
haresh
  • 486
  • 3
  • 18
  • Hi hares. did you solve your issue ? I am also facing same issue.. Please have a look into it. http://stackoverflow.com/questions/37115144/ios-xmpp-pubsub-not-receiving-events-while-publishing-node-to-my-subscribed-user – Mani murugan May 09 '16 at 12:06

1 Answers1

0

Client should indicate he wishes to receive notifications, as described in XEP-0060

In XMPPFramework you need to implement XMPPCapabilitiesDelegate and add younodename+notify to client capabilities. E.g. in your XMPPModule you need the following:

- (BOOL)activate:(XMPPStream *)aXmppStream
{
    if ([super activate:aXmppStream])
    {
        [xmppStream autoAddDelegate:self delegateQueue:moduleQueue toModulesOfClass:[XMPPCapabilities class]];
        return YES;
    }

    return NO;
}
- (NSArray *)myFeaturesForXMPPCapabilities:(XMPPCapabilities *)sender
{
    return @["myprotocolnode+notify"];
}
vitalyster
  • 4,980
  • 3
  • 19
  • 27
  • It will become static for only one node. But i want to receive notifications from all nods which are subscribed by me. – haresh Aug 20 '15 at 08:14
  • So you can query list of subscribed nodes and advertise +notify for each. Maybe you can configure some pubsub server component to make notifications enabled by default, but it is not recommended. – vitalyster Aug 20 '15 at 08:22
  • And in xmppModule class if we use XMPPCapabilities it gives forward class declaration error. As XMPPModule is superclass of XMPPCapabilities – haresh Aug 20 '15 at 08:25
  • you need to import XMPPCapabilites.h in your XMPPFramework.h – vitalyster Aug 20 '15 at 08:26
  • I do have it already there. I already have _xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:_xmppCapabilitiesStorage]; in Setupstream – haresh Aug 20 '15 at 08:28
  • myFeaturesForXMPPCapabilities is never getting called – haresh Aug 20 '15 at 08:29
  • You did not activate your own module or XMPPCapabilities module – vitalyster Aug 20 '15 at 08:31
  • I had activated just after initializing capabilities object with [_xmppCapabilities activate:_xmppStream]; – haresh Aug 20 '15 at 08:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/87455/discussion-between-haresh-and-vitalyster). – haresh Aug 20 '15 at 08:38