#import "AppDelegate.h"

//#import "DBAreaItem.h"

#pragma mark -

#pragma mark Private Interface

@interface AppDelegate()

typedef enum

{

AlertViewStyleConflict=,//登陆冲突

AlertViewStyleFailAuthenticate=,//登陆失败

AlertViewStyleDisconnect=//server链接失败

}AlertViewStyle;

@property(nonatomic,assign) int
AlertViewTag;

@end

#pragma markImplementation

@implementation AppDelegate

#pragma mark Properties

@synthesize window =_window;

@synthesizecacheinfo,settinginfo,serverInfo,userInfo;

//xmpp

@synthesize xmppStream;

@synthesize xmppRoster;

@synthesizexmppRosterStorage;

@synthesize xmppReconnect;

@synthesizexmppMessageArchivingCoreDataStorage;

@synthesizexmppMessageArchivingModule;

@synthesizejxlName,jxlNumber;

@synthesizexmppvCardStorage,xmppvCardTempModule,xmppvCardAvatarModule,xmppCapabilitiesStorage,xmppCapabilities;

#pragma mark UIApplicationDelegate

- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary
*)launchOptions

{

[selfmySetupStream];

return YES;

}

#pragma mark - actions

- (void)mySetupStream{

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

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

self.rosterArray
];

self.messageSenders=[[NSMutableDictionary
alloc];

self.allUsersDataDic=[[NSMutableDictionary
alloc];;

//
初始化xmppStream

if(xmppStream) {

return;

}

xmppStream
=[[XMPPStream alloc]init];

[xmppStreamaddDelegate: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];

[xmppRosteraddDelegate: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];

[xmppvCardTempModuleaddDelegate:self delegateQueue:dispatch_get_main_queue()];

[xmppvCardAvatarModuleaddDelegate:self delegateQueue:dispatch_get_main_queue()];

//
初始化capabilities

xmppCapabilitiesStorage
= [XMPPCapabilitiesCoreDataStoragesharedInstance];

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

xmppCapabilities.autoFetchHashedCapabilities
= YES;

xmppCapabilities.autoFetchNonHashedCapabilities=
NO;

//
初始化message

xmppMessageArchivingCoreDataStorage=[XMPPMessageArchivingCoreDataStorage
sharedInstance];

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

[xmppMessageArchivingModulesetClientSideMessageArchivingOnly:YES];

[xmppMessageArchivingModule
activate:xmppStream];

[xmppMessageArchivingModule
addDelegate:selfdelegateQueue: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];

[xmppvCardAvatarModuledeactivate];

[xmppCapabilities    
deactivate];

[xmppStream disconnect];

xmppStream = nil;

xmppReconnect = nil;

xmppRoster
= nil;

xmppRosterStorage =nil;

xmppvCardStorage =
nil;

xmppvCardTempModule
= nil;

xmppvCardAvatarModule =nil;

xmppCapabilities =
nil;

xmppCapabilitiesStorage =nil;

}

- (BOOL)myConnect//链接server,验证password并上线

{

if ([xmppStream
isConnected]) {

returnYES;

}

[self.rosterInfoDic removeAllObjects];

[self.allUsersDataDicremoveAllObjects];

[self.rosterArray removeAllObjects];

NSString
*strTransAite=[APPALL.cacheinfo.demailstringByReplacingOccurrencesOfString:@"@"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"];//设置server

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

NSError *error ;

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

[SVProgressHUDshowWithStatus:@"登录中..."];

error:&error])//XMPPStreamTimeoutNone

{

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

[SVProgressHUDshowErrorWithStatus:@"server连接失败"];

returnNO;

}

else{

returnYES;

}

}

- (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];

[[selfxmppStream]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 *)imagetoSize:(CGSize)theTize//图片压缩到指定CGSize大小

{

UIGraphicsBeginImageContext(theTize);

[image
,
,theTize.width,theTize.height)];

UIImage
*scaledImage =UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return scaledImage;

}

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

{

[self.allUsersDataDicremoveAllObjects];

; 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];//该keyword的数组

if(arrayWithgroupName)//存在该keyword的数组

{

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

{

[arrayWithgroupNameinsertObject:[NSNumber
];//在线好友加到数组第一个

}

else

{

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

}

}

else//不存在该keyword的数组

{

NSMutableArray*newArray=[[NSMutableArrayalloc]init];

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

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

}

}

}

#pragma mark - XMPPStreamDelegate

- (void)xmppStreamDidConnect:(XMPPStream *)sender

{

//验证password

NSError *error;

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

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

[xmppStreamauthenticateWithPassword: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];

[[selfxmppStream]sendElement:presence];

[xmppvCardTempModule
fetchvCardTempForJID:xmppStream.myJID];

self.lastFetchedvCard=xmppStream.myJID;

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

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

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

}

- (void)xmppStream:(XMPPStream *)senderdidNotAuthenticate:(NSXMLElement
*)error//

{

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

[SVProgressHUD
dismiss];

[selfmyDisconnect];

self.AlertViewTag
=AlertViewStyleFailAuthenticate;

[toolesshowSelectMsgBoxWithTitle:nilandMsg:@"登录失败,是否又一次登录?"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
children]lastObject];

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

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

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

NSArray *items = [querychildren];

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
]stringValue];

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

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

XMPPJID *object = [XMPPJID
jidWithString:jid];

NSMutableDictionary *dic=[[NSMutableDictionary
alloc]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;

[xmppvCardTempModulefetchvCardTempForJID:objectignoreStorage:YES];

}

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

}

//          //发送通知

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

[[NSNotificationCenterdefaultCenter]
postNotification: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:@"@"];

)return;

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

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

if([messageisChatMessageWithBody])//message

{

NSMutableDictionary*dict = [NSMutableDictionarydictionary];

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

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

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

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

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

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

[arrayaddObject:dict];

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

}

else

{

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

[array1addObject:dict];

}

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

NSNotification *notificationObject=[NSNotification
notificationWithName:@"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:@"@"];

)return;

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

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

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

if([messageisChatMessageWithBody])//message

{

NSLog(@"%@",message);

NSMutableDictionary*dict = [NSMutableDictionarydictionary];

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

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

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

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

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

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

[arrayaddObject:dict];

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

}

else

{

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

[array1addObject:dict];

}

//未读消息来源者

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

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

}

else

{

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

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

}

}

else//语音、图片类

{

NSLog(@"其它信息");

}

NSNotification *notificationObject=[NSNotification
notificationWithName:@"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 = [[presencefrom]
user];

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);

}elseif ([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);

}

}

[selfupdateallUsersDataDic_Group_Presence];

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

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

[[NSNotificationCenter
defaultCenter] postNotification:notificationObject];

}

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

{

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

DDXMLNode *errorNode = (DDXMLNode *)error;

for(DDXMLNode *node
in [errorNode children])

{

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

if([[nodename]
isEqualToString:@"conflict"])

{

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

//           [_timerinvalidate];

[self
myDisconnect];

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

[[NSNotificationCenterdefaultCenter]
postNotification:notificationObject];

self.AlertViewTag
= AlertViewStyleConflict;

[tooles
showSelectMsgBoxWithTitle:nilandMsg:@"您的账户已在其它手机上登录,您已被挤下线,请确定是否是您本人操作!是否又一次登录?"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);

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

}

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

{

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

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

}

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

- (void)xmppStreamWasToldToDisconnect:(XMPPStream*)sender

{

NSLog(@"xmppStreamWasToldToDisconnect");

}

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

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

{

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

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

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

//登陆不到server

//    error.userInfo ={

//       NSLocalizedDescription = "nodename nor servnameprovided, or not known";

//    }

[selfmyDisconnect];

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

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

}

else

{

[SVProgressHUDshowErrorWithStatus:@"好友server连接失败!"];

}

}

#pragma mark - XMPPReconnectDelegate

- (void)xmppReconnect:(XMPPReconnect *)senderdidDetectAccidentalDisconnect:(SCNetworkReachabilityFlags)connectionFlags

{

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

}

- (BOOL)xmppReconnect:(XMPPReconnect *)sendershouldAttemptAutoReconnect:(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(idmyItem
in [xmlData children])

{

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

if([myItemstringValue].length <=
)

{

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

}

else

{

NSLog(@"too long");

}

if([[myItemname]
isEqualToString:@"TITLE"])

{

titleString = [myItem
stringValue];

}

elseif([[myItem
name] isEqualToString:@"N"])

{

familyString = [myItem
stringValue];

}

elseif([[myItem
name] isEqualToString:@"PHOTO"])

{

photoString = [[myItem
];

}

}

//    头像image写入本地

NSString *PHOTOImagePath=[self
writeDateBase_64Image:photoStringWithFileName:jid.user
,
)];

NSMutableDictionary*dicObject=[[NSMutableDictionary
alloc]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.rosterInfoDicWithName:xmppStream.myJID.user AndTheType:@"plist"];

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

}

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

[[NSNotificationCenter
defaultCenter] postNotification:notificationObject];

}

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

{

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

}

//获取完善友列表

- (void)xmppRosterDidEndPopulating:(XMPPRoster*)sender

{

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

[SVProgressHUDshowSuccessWithStatus:@"登录成功"];

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

[SVProgressHUDdismiss];

}

[selfupdateallUsersDataDic_Group_Presence];

//发给BigDesktopViewController

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

[[NSNotificationCenter
defaultCenter] postNotification:notificationObject_1];

//发送通知BigFriendListViewController

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

[[NSNotificationCenter
defaultCenter] postNotification:notificationObject];

}

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

//{}

#pragma mark Core Data

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

- (NSManagedObjectContext*)managedObjectContext_roster

{

return [xmppRosterStoragemainThreadManagedObjectContext];

}

- (NSManagedObjectContext*)managedObjectContext_capabilities

{

return [xmppCapabilitiesStoragemainThreadManagedObjectContext];

}

#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 = [userdisplayName];

NSString *jidStrBare =[presence
fromStr];

NSString *body =
nil;

if (![displayName
isEqualToString:jidStrBare])

{

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

iOS xmpp的使用的更多相关文章

  1. iOS XMPP 通信协议实现 图形化直观感受

    第一次随笔,实在不知写点什么有用的东西,那就分享一下本人最近的研究所得吧! 是关于iOS-XMPP-通信协议的实现,具体代码比较复杂,三言两句也实在难表达清楚,网上已有很多关于iOS XMPP协议的讲 ...

  2. ios xmpp开发应用后台模式接收聊天信息处理方案

    ios xmpp开发应用后台模式接收聊天信息 最近在使用xmppframwork来实现一个聊天应用,碰到了一个问题,应用进入后台以后,就接收不到消息了: 怎么样才能使应用被切到后台时,应用中的网络连接 ...

  3. iOS xmpp协议实现聊天之openfire的服务端配置(一)

    今天弄这个openfire服务端的配置直接苦了一逼,只是好在最后最终配置好了.首先感谢@月光的尽头的博客给了我莫大的帮助. 切入正题,首先说一下iOS xmpp协议实现聊天openfireserver ...

  4. ios xmpp 发送语音图片解决方案

    ios xmpp 发送语音,图片解决方案,有需要的朋友可以参考下. 目前做IM多是用的xmpp. 因为项目需求需要实现语音和图片的发送. 发送语音图片有三种方法. 1,xmpp smack.文件传输方 ...

  5. iOS XMPP Framework 中文概述

    本篇文章翻译XMPP Framework中的Overview of the XMPP Framework部分 介绍 The framework is divided into 2 parts: 1. ...

  6. iOS - XMPP 的使用

    1.XMPP XMPP 是一个基于 Socket 通信的即时通讯的协议,它规范了即时通信在网络上数据的传输格式,比如登录,获取好友列表等等的格式.XMPP 在网络传输的数据是 XML 格式. 开发架构 ...

  7. iOS - XMPP Openfire 服务器的搭建

    前言 提前下载好相关软件,且安装目录最好安装在全英文路径下.如果路径有中文名,那么可能会出现一些莫名其妙的问题. 提前准备好的软件: jdk-8u91-macosx-x64.dmg mysql-5.7 ...

  8. 【iOS XMPP】使用XMPPFramewok(五):好友列表

    转自:http://www.cnblogs.com/dyingbleed/archive/2013/05/17/3082226.html 好友列表 好友列表,在 XMPP 中被称为 roster,花名 ...

  9. 【iOS XMPP】使用XMPPFramewok(四):收发消息

    转自:http://www.cnblogs.com/dyingbleed/archive/2013/05/16/3075105.html 收发消息 接收消息 通过实现 - (void)xmppStre ...

  10. 【iOS XMPP】使用XMPPFramewok(二):用户登录

    转自:http://www.cnblogs.com/dyingbleed/archive/2013/05/10/3069397.html 用户登录 准备工作 比较知名的开源XMPP服务器:一个是Ope ...

随机推荐

  1. pm2 start命令进阶详解

    在node的世界里面,并不存在nginx或者apache,甚至tomcat这种东东.一个node,本身就用几行代码,就可以启动个server进程,监听个端口,为大家提供web服务.这和传统的网站代码的 ...

  2. 5.1 qbxt 一测 T3

    反物质[问题描述] 物理学家有一种假设,世界上存在反物质,反物质遇到正常的物质会发生湮灭. 假设现在有 n 个粒子,每个粒子的种类用一个 m 以内的正整数表示.现在要将这些粒子按一定顺序放入一个封闭空 ...

  3. 深入理解JavaScript的设计模式

    使用适当的设计模式可以帮助你编写更好.更易于理解的代码.这样的代码也更容易维护.但是,重要的是不要过度使用它们.在使用设计模式之前,你应该仔细考虑你的问题是否符合设计模式. 当你开始一个新的项目时,你 ...

  4. c++_加法变乘法

    加法变乘法 我们都知道:1+2+3+ ... + 49 = 1225现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015 比如:1+2+3+...+10*11+12+...+27*28+29+ ...

  5. Spring Boot集成百度Ueditor

    遇到的问题: 1.将ueditor加入/static目录下,能正常显示,但是出现“请求后台配置项http错误,上传功能将不能正常使用!”(解决在下面,都是自定义上传的,如果需要官方的示例,我也无能为力 ...

  6. jQuery.data() 的实现方式

    jQuery.data() 的作用是为普通对象或 DOM Element 附加(及获取)数据. 下面将分三个部分分析其实现方式:     1. 用name和value为对象附加数据:即传入三个参数,第 ...

  7. python013 Python3 条件控制

    Python3 条件控制Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块.可以通过下图来简单了解条件语句的执行过程: if 语句Python中if语句的一 ...

  8. 使用SqlParameter.SqlDbType和SqlParameter.Size时需要注意的地方

    1.DbParameter类是SqlParameter和OracleParameter类的父类.DbParameter.Size用来获取或设置列中数据的最大尺寸(只对文本数据有用). 2.数据类型Ch ...

  9. FZU-2148-Moon Game,,几何计算~~

    Problem 2148 Moon Game Time Limit: 1000 mSec Memory Limit : 32768 KB  Problem Description Fat brothe ...

  10. [Go]程序实体

    Go语言中的程序实体包括变量.常量.函数.结构体.接口 1.常见声明变量的方式 package main import ( "flag" "fmt" ) fun ...