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.
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];
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"}]; }
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" ] }]; }
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.