Télécharger XMPPFramework et décompressez-le. Il y a plusieurs dossiers à l'intérieur. Ouvrez le dossier 'Xcode'> ouvrez le dossier 'iPhoneXMPP'> cliquez sur 'iPhoneXMPP.xcodeproj'> exécutez-le. Il demande d'abord les informations d'identification. Après une connexion réussie, il affichera votre liste de contacts. Cela fonctionne bien pour Gmail. Il y a un rappel méthode qui est appelée pour chaque message entrant:
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
user = [xmppRosterStorage userForJID:[message from] xmppStream:sender managedObjectContext:[self managedObjectContext_roster]];
if ([message isChatMessageWithBody])
{
NSString *body = [[message elementForName:@"body"] stringValue];
NSString *from = [[message attributeForName:@"from"] stringValue];
NSMutableDictionary *m = [[NSMutableDictionary alloc] init];
[m setObject:body forKey:@"msg"];
[m setObject:from forKey:@"sender"];
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
{
NSLog(@"Applications are in active state");
//send the above dictionary where ever you want
}
else
{
NSLog(@"Applications are in Inactive state");
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertAction = @"Ok";
localNotification.applicationIconBadgeNumber=count;
localNotification.alertBody =[NSString stringWithFormat:@"From:"%@\n\n%@",from,body];
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
//send the above dictionary where ever you want
}
}
}
Pour l'envoi de messages, nous devons écrire notre propre méthode où vous voulez:
-(void)sendMessage
{
NSString *messageStr =messageField.text;
if([messageStr length] > 0)
{
NSLog(@"Message sending fron Gmail");
NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue:messageStr];
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:@"destination address"];
[message addChild:body];
NSLog(@"message1%@",message);
[[self appDelegate].xmppSream sendElement:message];
}
}
Je suis sûr que le cadre XMPP a une Documentation? – Pripyat