一规伐、簡介XEP-0060
XEP-0060是一個(gè)XMPP協(xié)議擴(kuò)展來實(shí)現(xiàn)實(shí)現(xiàn)通用的 發(fā)布-訂閱 功能辱士。這個(gè)協(xié)議使 XMPP實(shí)體能在一個(gè)pubsub服務(wù)創(chuàng)建節(jié)點(diǎn)(主題)并發(fā)布信息到那些節(jié)點(diǎn)上子刮;然后一個(gè)事件通知(攜帶或未帶載荷)被廣播到所有訂閱了該節(jié)點(diǎn)的實(shí)體. PubSub因此堅(jiān)持了經(jīng)典的觀察者設(shè)計(jì)模式,并可以作為廣泛應(yīng)用的服務(wù)基礎(chǔ),包括新聞提要带欢,內(nèi)容整合洒忧,富出席信息蝴韭,地理位置,工作流系統(tǒng)熙侍,網(wǎng)絡(luò)管理系統(tǒng)榄鉴,以及任何其他需要事件通知的應(yīng)用履磨。
二、文檔
官方文檔:https://xmpp.org/extensions/xep-0060.html
中文翻譯文檔:http://wiki.jabbercn.org/XEP-0060
三庆尘、代碼塊
創(chuàng)建訂閱-推送對象
@property (nonatomic, strong) XMPPPubSub * xmppPubSub;
發(fā)布訂閱由MT發(fā)布剃诅,所以此代碼塊只有訂閱功能。
#pragma mark -- 推送驶忌、訂閱回調(diào)
- (void)setupPubSub:(NSString *)MT_Sn
{
//訂閱 推送 模塊
NSString * pubsub_auto_domain_name = @"pubsub.auto.hooca.com.cn";
XMPPJID * pubsub_jid = [XMPPJID jidWithString:pubsub_auto_domain_name];
_xmppPubSub = [[XMPPPubSub alloc]initWithServiceJID:pubsub_jid];
[_xmppPubSub activate:_xmppStream];
[_xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString * myjid = [defaults objectForKey:MYRESJID];
NSString * subnode = [NSString stringWithFormat:@"mt_%@_notify_node_id",MT_Sn];
XMPPJID * myresjid = [XMPPJID jidWithString:myjid];
[_xmppPubSub subscribeToNode:subnode withJID:myresjid];
}
- (void)cancelPubSub:(NSString *)MT_Sn
{
//訂閱 推送 模塊
NSString * pubsub_auto_domain_name = @"pubsub.auto.hooca.com.cn";
XMPPJID * pubsub_jid = [XMPPJID jidWithString:pubsub_auto_domain_name];
_xmppPubSub = [[XMPPPubSub alloc]initWithServiceJID:pubsub_jid];
[_xmppPubSub activate:_xmppStream];
[_xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString * myjid = [defaults objectForKey:MYRESJID];
NSString * subnode = [NSString stringWithFormat:@"mt_%@_notify_node_id",MT_Sn];
XMPPJID * myresjid = [XMPPJID jidWithString:myjid];
// [_xmppPubSub subscribeToNode:subnode withJID:myresjid];
[_xmppPubSub unsubscribeFromNode:subnode withJID:myresjid];
}