初识xmpp

#import "AppDelegate.h"

//#import "DBAreaItem.h"

#pragma mark –

#pragma mark Private Interface

@interface AppDelegate ()

typedef enum

{

    AlertViewStyleConflict=10,//登陆冲突

    AlertViewStyleFailAuthenticate=11,//登陆失败

    AlertViewStyleDisconnect=12//服务器链接失败

}AlertViewStyle;

@property(nonatomic,assign) int AlertViewTag;

@end

#pragma mark Implementation

@implementation AppDelegate

#pragma mark Properties

@synthesize window = _window;

@synthesize cacheinfo,settinginfo,serverInfo,userInfo;

//xmpp

@synthesize xmppStream;

@synthesize xmppRoster;

@synthesize xmppRosterStorage;

@synthesize xmppReconnect;

@synthesize xmppMessageArchivingCoreDataStorage;

@synthesize xmppMessageArchivingModule;

@synthesize jxlName,jxlNumber;

@synthesizexmppvCardStorage,xmppvCardTempModule,xmppvCardAvatarModule,xmppCapabilitiesStorage,xmppCapabilities;

#pragma mark UIApplicationDelegate

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

{

    [self mySetupStream];

    

    return YES;

}

#pragma mark – actions

– (void)mySetupStream{

    self.messageRecordDic = [[NSMutableDictionary alloc] init];//聊天信息的读取写在认证通过里面

//    self.myCardInfo = [[NSMutableDictionary alloc] init];

    self.rosterArray =[[NSMutableArray alloc] initWithCapacity:10];

    self.messageSenders=[[NSMutableDictionary alloc] initWithCapacity:10];

    self.allUsersDataDic=[[NSMutableDictionary alloc] initWithCapacity:10];;

    // 初始化 xmppStream

    if (xmppStream) {

        return;

    }

    xmppStream = [[XMPPStream alloc]init];

    [xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];

    //允许后台模式(注意ios模拟器上是不支持后台socket)

    xmppStream.enableBackgroundingOnSocket = YES;

    

    // 初始化 xmppReconnect

    xmppReconnect = [[XMPPReconnect alloc] init];

    

    // 初始化 xmppRosterStorage   roster

    xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc]init];

    xmppRoster = [[XMPPRoster alloc]initWithRosterStorage:xmppRosterStorage];

    [xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];

    xmppRoster.autoFetchRoster = YES;

    xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;

    

    // 初始化 vCard support

    xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance]; 

    xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];

    xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:xmppvCardTempModule];

    [xmppvCardTempModule addDelegate:self delegateQueue:dispatch_get_main_queue()];

    [xmppvCardAvatarModule addDelegate:self delegateQueue:dispatch_get_main_queue()];

    

    // 初始化 capabilities

    xmppCapabilitiesStorage = [XMPPCapabilitiesCoreDataStorage sharedInstance];

    xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:xmppCapabilitiesStorage];

    xmppCapabilities.autoFetchHashedCapabilities = YES;

    xmppCapabilities.autoFetchNonHashedCapabilities = NO;

    

    // 初始化 message

    xmppMessageArchivingCoreDataStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];

    xmppMessageArchivingModule = [[XMPPMessageArchiving alloc]initWithMessageArchivingStorage:xmppMessageArchivingCoreDataStorage];

    [xmppMessageArchivingModule setClientSideMessageArchivingOnly:YES];

    [xmppMessageArchivingModule activate:xmppStream];

    [xmppMessageArchivingModule addDelegate:self delegateQueue:dispatch_get_main_queue()];

    // 激活xmpp的模块

    [xmppReconnect         activate:xmppStream];

    [xmppRoster            activate:xmppStream];

    [xmppvCardTempModule   activate:xmppStream];

    [xmppvCardAvatarModule activate:xmppStream];

    [xmppCapabilities      activate:xmppStream];

    

      //下面这两个根据你自己配置需要来设置

//    allowSelfSignedCertificates = NO;

//    allowSSLHostNameMismatch = NO;

    

}

– (void)myTeardownStream//

{

[xmppStream removeDelegate:self];

[xmppRoster removeDelegate:self];

 

[xmppReconnect         deactivate];

[xmppRoster            deactivate];

[xmppvCardTempModule   deactivate];

[xmppvCardAvatarModule deactivate];

[xmppCapabilities      deactivate];

 

[xmppStream disconnect];

xmppStream = nil;

xmppReconnect = nil;

    xmppRoster = nil;

xmppRosterStorage = nil;

xmppvCardStorage = nil;

    xmppvCardTempModule = nil;

xmppvCardAvatarModule = nil;

xmppCapabilities = nil;

xmppCapabilitiesStorage = nil;

}

– (BOOL)myConnect//链接服务器,验证密码并上线

{

    if ([xmppStream isConnected]) {

        return YES;

    }

    [self.rosterInfoDic removeAllObjects];

    [self.allUsersDataDic removeAllObjects];

    [self.rosterArray removeAllObjects];

    NSString *strTransAite=[APPALL.cacheinfo.demail stringByReplacingOccurrencesOfString:@"@"withString:@"$"];

    NSLog(@"%@",strTransAite);

    XMPPJID *myjid = [XMPPJID jidWithUser:strTransAite domain:@"eim.abc.com.cn" resource:@"GIMI0.6"  ];

    [xmppStream setMyJID:myjid];

    [xmppStream setHostName:@"eim.abc.com.cn"];//设置服务器

    // [[self xmppStream] setHostPort:5222];

    NSError *error ;

    //NSLog(@"xmppStream=%@",xmppStream);

    [SVProgressHUD showWithStatus:@"登录中…"];

    if (![xmppStream connectWithTimeout:1 error:&error])//XMPPStreamTimeoutNone

    {

        NSLog(@"my connected error : %@",error.description);

        [SVProgressHUD showErrorWithStatus:@"服务器连接失败"];

        return NO;

    }

    else{

        return YES;

    }

}

– (void)myDisconnect//断开连接

{

[self myGoOffline];

[xmppStream disconnect];

}

– (void)myDeleteRecord//清楚聊天,信息记录

{

    [self.messageRecordDic removeAllObjects];

    [self.messageSenders removeAllObjects];

}

– (void)getMyQueryRoster//Request FriendList

{

    NSLog(@"request friendlist…");

    NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:roster"];

    NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];

    XMPPJID *myJID = self.xmppStream.myJID;

    [iq addAttributeWithName:@"from" stringValue:myJID.description];

    [iq addAttributeWithName:@"to" stringValue:myJID.domain];

    [iq addAttributeWithName:@"id" stringValue:nil];

    [iq addAttributeWithName:@"type" stringValue:@"get"];

    [iq addChild:query];

    [self.xmppStream sendElement:iq];

    

}

– (void)myGoOnline//上线

{

    //简单上线

    XMPPPresence *presence = [XMPPPresence presence];

    [[self xmppStream] sendElement:presence];

}

– (void)myGoOffline//下线

{

XMPPPresence *presence = [XMPPPresence presenceWithType:@"unavailable"];

[[self xmppStream] sendElement:presence];

}

– (NSString *)writeDateBase_64Image:(NSString *)photoString WithFileName 🙁NSString *)theImageName Size 🙁CGSize)theSize

{

    if ([photoString isEqualToString:@""]) {

        NSLog(@"writeDateBase_64Image 没有头像");

        return @"";

    }

    //压缩data再写入本地

    NSData *data=[photoString base64DecodedData];

    UIImage *aimage=[self scaleImage:[UIImage imageWithData:data] toSize:theSize];

    NSData *dataAfterscale=UIImageJPEGRepresentation(aimage, 1.0);

   return  [DataPlist writeData:dataAfterscale ToTMPWithSubFloderName:@"headImageCache"FileName:theImageName];

}

-(UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)theTize//图片压缩到指定CGSize大小

{

    UIGraphicsBeginImageContext(theTize);

    [image drawInRect:CGRectMake(00, theTize.width, theTize.height)];

    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return scaledImage;

}

– (void)updateallUsersDataDic_Group_Presence//更新分组+在线、离线状态好友数据

{

    [self.allUsersDataDic removeAllObjects];

    for(int i = 0; i < self.rosterArray.count; i++)

    {

        NSMutableDictionary *adic = [self.rosterArray objectAtIndex:i];

        XMPPJID *ajid=[adic objectForKey:@"object"];

        if ([ajid.user isEqualToString:xmppStream.myJID.user])

        {

            continue;

        }

        NSString *groupName=[adic objectForKey:@"group"];//分组名

        NSString *presenceType=[adic objectForKey:@"presenceType"];//状态

        NSMutableArray *arrayWithgroupName=[self.allUsersDataDic objectForKey:groupName];//该关键字的数组

        if (arrayWithgroupName)//存在该关键字的数组

        {

            

            if ([presenceType isEqualToString:@"yes"])

            {

                [arrayWithgroupName insertObject:[NSNumber numberWithInt:i] atIndex:0];//在线好友加到数组第一个

            }

            else

            {

                [arrayWithgroupName addObject:[NSNumber numberWithInt:i]];//离线的好友,加到数组最后一个

            }

        }

        else//不存在该关键字的数组

        {

            NSMutableArray *newArray=[[NSMutableArray alloc]init];

            [newArray addObject:[NSNumber numberWithInt:i]];//在线或者离线的好友,加到空白数组里面

            [self.allUsersDataDic setObject:newArray forKey:groupName];//groupName=newArray,添加到allUsersDataDic

        }

        

    }

}

#pragma mark – XMPPStreamDelegate

– (void)xmppStreamDidConnect:(XMPPStream *)sender

{

    //验证密码

    NSError *error;

    NSString *md5password= [APPALL.cacheinfo.dpassword MD5Digest];

    NSLog(@"%s–\nmd5password=%@",__func__,md5password);

    [xmppStream authenticateWithPassword:md5password error:&error];

}

– (void)xmppStreamDidAuthenticate:(XMPPStream *)sender

{

    NSLog(@"验证通过%s–\nsender.hostName=%@ remoteJID.description=%@  sender.keepAliveInterval=%f",__func__,sender.hostName,sender.remoteJID.description,sender.keepAliveInterval);

    XMPPPresence *presence = [XMPPPresence presence];

    [[self xmppStream] sendElement:presence];

    

    [xmppvCardTempModule fetchvCardTempForJID:xmppStream.myJID];

    self.lastFetchedvCard=xmppStream.myJID;

//       self.rosterInfoDic=[DataPlist openDPFromDocumentsWithName:xmppStream.myJID.user AndTheType:@"plist"];//我的(xmppStream.myJID.user的)好友信息

    self.rosterInfoDic=[DataPlist openPlistFromDocumentWithName:xmppStream.myJID.user AndTheType:@"plist"];//我的(xmppStream.myJID.user的)好友信息

    NSLog(@"验证通过,本地好友信息数目=%d",self.rosterInfoDic.count);

}

– (void)xmppStream🙁XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error//

{

    NSLog(@"验证失败 didNotAuthenticate:%@",error.description);

    [SVProgressHUD dismiss];

    [self myDisconnect];

    self.AlertViewTag = AlertViewStyleFailAuthenticate;

    [tooles showSelectMsgBoxWithTitle:nil andMsg:@"登录失败,是否重新登录?" andDelegate:self];

}

– (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq//返回IQ(好友列表、)

{

    NSLog(@"–type:%@",iq.type);

//    NSLog(@"–%@",[iq.childElement children]);

//    NSLog(@"–child:%@",iq.childElement );

    if ([@"result" isEqualToString:iq.type]) {

        NSXMLElement *query = iq.childElement;

        NSXMLElement *aitem=[[query childrenlastObject];

        NSString *ajid = [aitem attributeStringValueForName:@"jid"];

        NSLog(@"ajid=%@",ajid);

        if ([@"query" isEqualToString:query.name]&&ajid) {

            NSArray *items = [query children];

            NSLog(@"iq.to=%@  items.count=%d ",iq.to,items.count);

            [self.rosterArray removeAllObjects];

            for (NSXMLElement *item in items) {

//                "\U9510\U6770\U7f51\U683c",

                NSString *groupName= [[item.children objectAtIndex:0]stringValue];

                NSString *jid = [item attributeStringValueForName:@"jid"];

                NSLog(@"分组groupName=%@",groupName);

                XMPPJID *object = [XMPPJID jidWithString:jid];

                NSMutableDictionary *dic=[[NSMutableDictionaryalloc]initWithObjectsAndKeys:object,@"object",@"no",@"presenceType",groupName,@"group"nil];

                [self.rosterArray addObject:dic];

                //

                if (![self.rosterInfoDic objectForKey:object.user]&&object)//if本地数据没有该好友信息,就请求fetchvCardTempForJID

                {

                    self.lastFetchedvCard=nil,self.lastFetchedvCard=object;

                 [xmppvCardTempModule fetchvCardTempForJID:object ignoreStorage:YES];

                }

//                NSLog(@"FAMILY=%@\n self.lastFetchedvCard=%@ \nobject.description=%@ ",[[self.rosterInfoDic objectForKey:object.user] objectForKey:@"FAMILY"],self.lastFetchedvCard,object.description);

            }

//            //发送通知

            NSNotification *notificationObject =[NSNotificationnotificationWithName:@"upDateListData"object:nil];

            [[NSNotificationCenter defaultCenterpostNotification:notificationObject];

        }

        if ([@"vCard" isEqualToString:query.name])

        {

        }

    }

    return YES;

}

– (void)xmppStream:(XMPPStream *)sender didSendMessage:(XMPPMessage *)message

{

    NSString *msg = [[message elementForName:@"body"stringValue];

    NSString *from = [[message attributeForName:@"from"stringValue];

    NSString *to = [[message attributeForName:@"to"] stringValue];

    NSString *type= [[message attributeForName:@"type"stringValue];

    NSRange range=[to rangeOfString:@"@"];

    if(range.length==0)return;

    NSString *toSimple=[to substringToIndex:range.location];

    NSLog(@"发送给%@的消息: %@ (消息类型:%@)",toSimple,msg,type);

    if ([message isChatMessageWithBody])//message

    {

        NSMutableDictionary *dict = [NSMutableDictionary dictionary];

        [dict setObject:from forKey:@"sender"];

        [dict setObject:msg forKey:@"msg"];

        [dict setObject:@"text" forKey:@"type"];

        [dict setObject:[NSDate dateforKey:@"date"];

        if (![self.messageRecordDic objectForKey:toSimple]&&dict) {

            NSMutableArray *array=[[NSMutableArray alloc]init];

            [array addObject:dict];

            [self.messageRecordDic setObject:array forKey:toSimple];

        }

        else

        {

            NSMutableArray *array1=[self.messageRecordDic objectForKey:toSimple];

            [array1 addObject:dict];

        }

        [self.messageSenders setObject:@"0" forKey:toSimple];//将最近联系人放入messageSenders

        NSNotification *notificationObject =[NSNotificationnotificationWithName:@"messageGetting"object:nil];

        [[NSNotificationCenter defaultCenter]postNotification:notificationObject];

    }

}

– (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message

{

    NSString *msg = [[message elementForName:@"body"stringValue];

    NSString *from = [[message attributeForName:@"from"stringValue];

    NSString *type= [[message attributeForName:@"type"stringValue];

    NSRange range=[from rangeOfString:@"@"];

    if(range.length==0)return;

    NSString *fromSimple=[from substringToIndex:range.location];

    NSLog(@"接受%@的消息: %@ (消息类型:%@)",fromSimple,msg,type);

    NSLog(@"接受消息%@",message);

    if ([message isChatMessageWithBody])//message

    {

        NSLog(@"%@",message);

        NSMutableDictionary *dict = [NSMutableDictionary dictionary];

        [dict setObject:fromSimple forKey:@"sender"];

        [dict setObject:msg forKey:@"msg"];

        [dict setObject:@"text" forKey:@"type"];

        [dict setObject:[NSDate dateforKey:@"date"];

        if (![self.messageRecordDic objectForKey:fromSimple]&&dict) {

            NSMutableArray *array=[[NSMutableArray alloc]init];

            [array addObject:dict];

            [self.messageRecordDic setObject:array forKey:fromSimple];

        }

        else

        {

            NSMutableArray *array1=[self.messageRecordDic objectForKey:fromSimple];

            [array1 addObject:dict];

        }

        //未读消息来源者

        if (![self.messageSenders objectForKey:fromSimple]) {

            [self.messageSenders setObject:@"1" forKey:fromSimple];

        }

        else

        {

            int number=[[self.messageSenders objectForKey:fromSimple] intValue]+1;

            [self.messageSenders setObject:[NSString stringWithFormat:@"%d",number] forKey:fromSimple];

        }

    }

    else//语音、图片类

    {

        NSLog(@"其他信息");

    }

    NSNotification *notificationObject =[NSNotificationnotificationWithName:@"messageGetting"object:nil];

    [[NSNotificationCenter defaultCenter]postNotification:notificationObject];

}

– (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence

{

    NSLog(@"___%s",__func__);

       NSString *presenceType = [presence type]; //online/offline

    //当前用户

    NSString *userId = [[[APPALL xmppStream]myJID]user] ;

    //在线用户

    NSString *presenceFromUser = [[presence fromuser];

    if (![presenceFromUser isEqualToString:userId]) {

        //在线状态

        if ([presenceType isEqualToString:@"available"]) {

            //用户列表委托

            for (NSMutableDictionary *dic in self.rosterArray) {

                XMPPJID *object = [dic objectForKey:@"object"];

                if ([object.user hasPrefix:presenceFromUser]) {

                    [dic setObject:@"yes" forKey:@"presenceType" ];

                }

            }

            NSLog(@"%@上线了",presenceFromUser);

        }else if ([presenceType isEqualToString:@"unavailable"]) {

            //用户列表委托

            for (NSMutableDictionary *dic in self.rosterArray) {

                XMPPJID *object = [dic objectForKey:@"object"];

                if ([object.user hasPrefix:presenceFromUser]) {

                    [dic setObject:@"no" forKey:@"presenceType" ];

                }

            }

            NSLog(@"%@下线了",presenceFromUser);

        }

    }

    [self updateallUsersDataDic_Group_Presence];

    //发送好友列表刷新通知

    NSNotification *notificationObject =[NSNotificationnotificationWithName:@"upDateListData"object:nil];

    [[NSNotificationCenter defaultCenterpostNotification:notificationObject];

    

}

– (void)xmppStream:(XMPPStream *)sender didReceiveError:(NSXMLElement *)error

{

    NSLog(@"didReceiveError  description: %@",error.description);

    DDXMLNode *errorNode = (DDXMLNode *)error;

    for(DDXMLNode *node in [errorNode children])

    {

        //若错误节点有【冲突】

        if([[node nameisEqualToString:@"conflict"])

        {

            //停止轮训检查链接状态

//            [_timer invalidate];

            [self myDisconnect];

            NSNotification *notificationObject =[NSNotificationnotificationWithName:@"upDateListData"object:nil];

            [[NSNotificationCenter defaultCenterpostNotification:notificationObject];

            self.AlertViewTag = AlertViewStyleConflict;

            [tooles showSelectMsgBoxWithTitle:nil andMsg:@"您的账户已在其他手机上登录,您已被挤下线,请确定是否是您本人操作!是否重新登录?andDelegate:self];

        }

    }

}

– (void)xmppStream:(XMPPStream *)sender didSendIQ🙁XMPPIQ *)iq

{

    NSLog(@"didSendIQ:%@",iq.description);

//    1  didSendIQ:

//    2  didSendIQ:

//    3、(手动发送好友列表请求)  didSendIQ:}

– (void)xmppStream:(XMPPStream *)sender didFailToSendMessage:(XMPPMessage *)message error:(NSError*)error

{

    NSLog(@"didFailToSendMessage:%@",error.description);

    [SVProgressHUD showErrorWithStatus:@"消息发送失败"];

}

– (void)xmppStream:(XMPPStream *)sender didFailToSendPresence:(XMPPPresence *)presence error:(NSError*)error

{

    NSLog(@"didFailToSendPresence:%@",error.description);

    [SVProgressHUD showErrorWithStatus:@"状态更新失败"];

}

//[xmppStream disconnect]时会执行;掉线、断网故障时不执行

– (void)xmppStreamWasToldToDisconnect:(XMPPStream *)sender

{

    NSLog(@"xmppStreamWasToldToDisconnect");

}

//[xmppStream disconnect]、掉线、断网故障时执行

– (void)xmppStreamDidDisconnect:(XMPPStream *)sender withError:(NSError *)error

{

    NSString *str=[NSString stringWithFormat:@"服务器连接失败%@",[error.userInfoobjectForKey:@"NSLocalizedDescription"]];

    NSLog(@"%s–=%@—\n error =%@",__func__,str,error);

    NSLog(@"error.userInfo =%@",error.userInfo);

    //登陆不到服务器

//    error.userInfo ={

//        NSLocalizedDescription = "nodename nor servname provided, or not known";

//    }

    [self myDisconnect];

    if ([error.userInfo objectForKey:@"NSLocalizedDescription"]) {

        [SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"NSLocalizedDescription"]];

    }

    else

    {

        [SVProgressHUD showErrorWithStatus:@"好友服务器连接失败!"];

    }

}

#pragma mark – XMPPReconnectDelegate

– (void)xmppReconnect:(XMPPReconnect *)sender didDetectAccidentalDisconnect:(SCNetworkReachabilityFlags)connectionFlags

{

    NSLog(@"didDetectAccidentalDisconnect:%u",connectionFlags);

}

– (BOOL)xmppReconnect:(XMPPReconnect *)sender shouldAttemptAutoReconnect:(SCNetworkReachabilityFlags)reachabilityFlags

{

    NSLog(@"shouldAttemptAutoReconnect:%u",reachabilityFlags);

    return YES;

}

#pragma mark-XMPPvCardTempModuleDelegate名片信息

– (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule

        didReceivevCardTemp:(XMPPvCardTemp *)vCardTemp

                     forJID:(XMPPJID *)jid

{

//    NSLog(@"%s",__func__);

    NSXMLElement *xmlData=(NSXMLElement *)vCardTemp;

    NSString *titleString = @"这个用户很懒,没有签名!";

    NSString *familyString = @"无名用户";

    NSString *photoString = @"";

    for(id myItem in [xmlData children])

    {

        NSLog(@"myItem name=%@",[myItem name]);

        if([myItem stringValue].length <= 100)

        {

//            NSLog(@"valuelalala:%@",[myItem stringValue]);

        }

        else

        {

            NSLog(@"too long");

        }

        if([[myItem nameisEqualToString:@"TITLE"])

        {

            titleString = [myItem stringValue];

        }

        else if([[myItem nameisEqualToString:@"N"])

        {

            familyString = [myItem stringValue];

        }

        else if([[myItem nameisEqualToString:@"PHOTO"])

        {

            photoString = [[myItem stringValuesubstringFromIndex:5];

        }

    }

//    头像image 写入本地

    NSString *PHOTOImagePath=[self writeDateBase_64Image:photoString WithFileName:jid.userSize:CGSizeMake(8888)];

    NSMutableDictionary *dicObject=[[NSMutableDictionaryalloc]initWithObjectsAndKeys:titleString,@"TITLE",familyString,@"FAMILY",PHOTOImagePath,@"PHOTO"nil];

    [self.rosterInfoDic setObject:dicObject forKey:jid.user];//

    //family photopath title 写入本地

    NSLog(@"forJID:(XMPPJID *)jid=%@   \n self.lastFetchedvCard=%@   \n ",jid.user,self.lastFetchedvCard.user);

    if ([self.lastFetchedvCard.user isEqualToString:jid.user])//(在最后一次名片请求的时候,写入本地,)

    {

//        [DataPlist writeDP:self.rosterInfoDic WithName:xmppStream.myJID.user AndTheType:@"plist"];

        [DataPlist writePlistToDocumentWithDic:self.rosterInfoDic WithName:xmppStream.myJID.userAndTheType:@"plist"];

    }

    NSNotification *notificationObject =[NSNotificationnotificationWithName:@"upDateListData"object:nil];

    [[NSNotificationCenter defaultCenterpostNotification:notificationObject];

}

– (void)xmppvCardTempModuleDidUpdateMyvCard:(XMPPvCardTempModule *)vCardTempModule//更新名片

{

    NSLog(@"%s–%@",__func__,vCardTempModule);

}

//获取完好友列表

– (void)xmppRosterDidEndPopulating:(XMPPRoster *)sender

{

    NSLog(@"获取完毕好友列表");

    [SVProgressHUD showSuccessWithStatus:@"登录成功"];

    if ([self.lastFetchedvCard.user isEqualToString:xmppStream.myJID.user]) {

        [SVProgressHUD dismiss];

    }

    [self updateallUsersDataDic_Group_Presence];

    //发给BigDesktopViewController

    NSNotification *notificationObject_1 =[NSNotificationnotificationWithName:@"DidAuthenticate"object:nil];

    [[NSNotificationCenter defaultCenterpostNotification:notificationObject_1];

    //发送通知BigFriendListViewController

    NSNotification *notificationObject =[NSNotificationnotificationWithName:@"upDateListData"object:nil];

    [[NSNotificationCenter defaultCenterpostNotification:notificationObject];

}

//- (XMPPvCardTemp *)myvCardTempForXMPPStream:(XMPPStream *)stream

//{}

#pragma mark Core Data

– (NSManagedObjectContext *)managedObjectContext_roster

{

return [xmppRosterStorage mainThreadManagedObjectContext];

}

– (NSManagedObjectContext *)managedObjectContext_capabilities

{

return [xmppCapabilitiesStorage mainThreadManagedObjectContext];

}

#pragma mark – XMPPRosterDelegate

– (void)xmppRoster:(XMPPRoster *)sender didReceivePresenceSubscriptionRequest:(XMPPPresence *)presence

{

    NSLog(@"好友状态更改–%s",__func__);

}

– (void)xmppRoster:(XMPPRoster *)sender didReceiveBuddyRequest:(XMPPPresence *)presence//接受好友请求

{

NSLog(@"%s",__func__);

XMPPUserCoreDataStorageObject *user = [xmppRosterStorage userForJID:[presence from]

                                                        xmppStream:xmppStream

                                              managedObjectContext:[self managedObjectContext_roster]];

 

NSString *displayName = [user displayName];

NSString *jidStrBare = [presence fromStr];

NSString *body = nil;

 

if (![displayName isEqualToString:jidStrBare])

{

body = [NSString stringWithFormat:@"Buddy request from %@

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注