国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

XMPP增加刪除好友

2019-11-14 18:41:56
字體:
來源:轉載
供稿:網友

  在現階段的通信服務中,各種標準都有,因此會出現無法實現相互連通,而XMPP(Extensible Message and PResence Protocol)協議的出現,實現了整個及時通信服務協議的互通。有了這個協議之后,使用任何一個組織或者個人提供的即使通信服務,都能夠無障礙的與其他的及時通信服務的用戶進行交流。例如google 公司2005年推出的Google talk就是一款基于XMPP協議的即時通信軟件。下面我們就談論一下如何簡單的使用XMPP的好友添加

1、在XMPPFramework.h中將需要用到的頭文件打開

 

2、在storyboard創建好友列表界面和增加好友界面

 創建和增加的時候應該注意兩者之間的連線:

 

3、定義查詢結果存儲器并且進行初始化

NSFetchedResultsController * fetch;    AppDelegate * delegate=[UIapplication sharedApplication].delegate;            //獲取上下文    NSManagedObjectContext * context=[delegate.rosterStorage mainThreadManagedObjectContext];        //獲取請求NSFetchRequest    NSFetchRequest * request=[NSFetchRequest fetchRequestWithEntityName:@"XMPPUserCoreDataStorageObject"];        //增加排序字段    NSSortDescriptor * des=[NSSortDescriptor sortDescriptorWithKey:@"sectionNum" ascending:YES];    [request setSortDescriptors:@[des]];        //對fetch進行初始化    fetch=[[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:@"sectionNum" cacheName:nil];        //設置代理    [fetch setDelegate:self];        //開始查詢    [fetch performFetch:nil];

4、創實現tableView的代理方法

#pragma mark - Table view data source- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {    return fetch.sections.count;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {     id<NSFetchedResultsSectionInfo> sections=fetch.sections[section];    return [sections numberOfObjects] ;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tabble" ];     XMPPUserCoreDataStorageObject * user=[fetch objectAtIndexPath:indexPath];    cell.textLabel.text=user.displayName;            return cell;}//返回分組數據信息,根據字段type來控制當前的狀態-(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{      id<NSFetchedResultsSectionInfo> info= [[fetch sections] objectAtIndex:section];    NSString * type=nil;        if ([info.name isEqualToString:@"0"]) {        type=@"在線";    }else {         type=@"離線";    }        return type;}

5、刪除好友

 

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{    return YES;}//通過花名冊對象對當前的好友進行刪除操作-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{    if (editingStyle==UITableViewCellEditingStyleDelete) {        AppDelegate * delegate=[UIApplication sharedApplication] .delegate;                XMPPUserCoreDataStorageObject * user=[fetch objectAtIndexPath:indexPath];                [delegate.roster removeUser:user.jid];            }}

6、增加好友

- (IBAction)add {    //獲取好友名稱    NSString * name=self.friends.text;     //獲取好友名稱    AppDelegate * delegate=[UIApplication sharedApplication].delegate;    XMPPJID * jid=[XMPPJID jidWithString:name];    if ([delegate.rosterStorage userExistsWithJID:jid xmppStream:delegate.stream]) {        NSLog(@"好友已經存在了");    }else{        //增加好友        [delegate.roster subscribePresenceToUser:jid];    }}

 

  想要了解更多內容的小伙伴,可以點擊查看源碼,親自運行測試。

  疑問咨詢或技術交流,請加入官方QQ群:JRedu技術交流 (452379712)

 

作者:杰瑞教育
出處:http://m.survivalescaperooms.com/jerehedu/ 
本文版權歸煙臺杰瑞教育科技有限公司和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 密云县| 弥勒县| 新蔡县| 福贡县| 务川| 旬邑县| 思茅市| 叶城县| 库车县| 牟定县| 丽水市| 马鞍山市| 大丰市| 遵义市| 睢宁县| 鹤庆县| 石嘴山市| 周至县| 烟台市| 新密市| 衡阳县| 卫辉市| 霍山县| 永州市| 会泽县| 宝兴县| 黑水县| 乌拉特中旗| 石楼县| 大港区| 海城市| 新营市| 沙坪坝区| 山阳县| 木兰县| 乌兰浩特市| 五常市| 吉隆县| 咸丰县| 尼木县| 东丽区|