xmppframework for iOS client(五) 添加AutoPing


為了監聽服務器是否有效,增加心跳監聽。用XEP-0199協議,在XMPPFrameWork框架下,封裝了 XMPPAutoPing 和 XMPPPing兩個類都可以使用,因為XMPPAutoPing已經組合進了XMPPPing類,所以XMPPAutoPing使用起來更方便。

首先,導入頭文件 

#import "XMPPAutoPing.h"

聲明成員變量和屬性

@interface XMPPConnectManeger : NSObject<XMPPAutoPingDelegate>

{

     XMPPAutoPing *_xmppAutoPing;

}

@property  (nonatomic, retain) XMPPAutoPing *xmppAutoPing;

在實現文件中

@synthesize xmppStream = _xmppStream;

@synthesize xmppAutoPing = _xmppAutoPing;

//初始化並啟動ping

-(void)autoPingProxyServer:(NSString*)strProxyServer

{

    _xmppAutoPing = [[XMPPAutoPingalloc] init];

    [_xmppAutoPingactivate:_xmppStream];

    [_xmppAutoPingaddDelegate:selfdelegateQueuedispatch_get_main_queue()];

    _xmppAutoPing.respondsToQueries = YES;

    _xmppAutoPing.pingInterval=2;//ping 間隔時間

    if (nil != strProxyServer)

    {

       _xmppAutoPing.targetJID = [XMPPJID jidWithString: strProxyServer ];//設置ping目標服務器,如果為nil,則監聽socketstream當前連接上的那個服務器

    }

}

//卸載監聽

 [_xmppAutoPing   deactivate];

  [_xmppAutoPing   removeDelegate:self];

   _xmppAutoPing = nil;

//ping XMPPAutoPingDelegate的委托方法:

- (void)xmppAutoPingDidSendPing:(XMPPAutoPing *)sender

{

    NSLog(@"- (void)xmppAutoPingDidSendPing:(XMPPAutoPing *)sender");

}

- (void)xmppAutoPingDidReceivePong:(XMPPAutoPing *)sender

{

    NSLog(@"- (void)xmppAutoPingDidReceivePong:(XMPPAutoPing *)sender");

}

 

- (void)xmppAutoPingDidTimeout:(XMPPAutoPing *)sender

{

    NSLog(@"- (void)xmppAutoPingDidTimeout:(XMPPAutoPing *)sender");

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM