1. 关于xmpp文件传送,用xmppframework框架怎么发送及接收文件
每个客户端的实现方式不一样,你得试试jingle协议。
你的采纳是我前进的动力,
记得好评和采纳,答题不易,互相帮助,
手机提问的朋友在客户端右上角评价点(满意)即可.
如果你认可我的回答,请及时点击(采纳为满意回答)按钮!!
2. iOS 使用xmppframework怎么获取消息的发送时间
添加一个发送时间的元素 加到 message 中 与body 同级
接收消息的时候 收到的那个消息 才是正确的发送时间
将收到消息的时间当作发送时间处理吧,其实前端只要知道啥时候收到就可以了。
3. IOS XMPP通信协议怎么拒绝对方添加我为好友
发送一个type为unsubscribed的presence消息就是拒绝对方的请求,示例:
<presence from='[email protected]'
id='ul4bs71n'
to='[email protected]'
type='unsubscribed'/>
你可以看xmpp的协议标准文档,里面都有详细的说明,
4. ios怎样在xmpp自带的数据库里面插入数据
点击登录之后,验证成功就会跳到好友页面。这个时候需要显示你已经有的好友。
那么在tableViewCell中显示好友姓名,需要数据源,数据源从服务器获看你是否有好友,检索到你的好友后把他显示在列表上。
xmpp中管理好友的类是 XMPPRoster,并且使用coredata来储存好友,达到数据持久化的效果。
那么我们可以将获取储存好友的仓库和xmppRoster对象的初始化封装在XMPPManager中。
在.h文件中声明:
//好友管理
@property(nonatomic,strong)XMPPRoster xmppRoster;
遵循代理:
@interface XMPPManager : NSObject<XMPPStreamDelegate,XMPPRosterDelegate>
在 .m文件中重写init方法中:
//2.好友管理//获得一个存储好友的CoreData仓库,用来数据持久化 XMPPRosterCoreDataStorage rosterCoreDataStorage = [XMPPRosterCoreDataStorage sharedInstance];//初始化xmppRoster self.xmppRoster = [[XMPPRoster alloc]initWithRosterStorage:rosterCoreDataStorage dispatchQueue:dispatch_get_main_queue()];//激活 [self.xmppRoster activate:self.xmppStream];//设置代理 [self.xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
接收好友请求。
将接收到好友请求的方法也封装在XMPPManager中:
// 收到好友请求执行的方法-(void)xmppRoster:(XMPPRoster )sender :(XMPPPresence )presence{ self.fromJid = presence.from; UIAlertView alert = [[UIAlertView alloc]initWithTitle:@"提示:有人添加你" message:presence.from.user delegate:self cancelButtonTitle:@"拒绝" otherButtonTitles:@"OK", nil]; [alert show];}
-(void)alertView:(UIAlertView )alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ switch (buttonIndex) { case 0: [self.xmppRoster :self.fromJid]; break; case 1: [self.xmppRoster :self.fromJid andAddToRoster:YES]; break; default: break; }}
添加好友,添加的好友必须是服务器上存在的用户,需要看对方是否同意。对方同意之后,刷新好友列表,显示出来,同时在服务器上也要添加,这里服务器上用的是coredata来存储个人的好友信息。
好友页面实现文件,遵循代理,数据源数组
在viewDidLoad中完成初始化数组,设置代理和添加好友按钮
这里简化了添加好友,写死了只能添加“张三”,如果需要添加更多,可以写成借口
接下来是tableview数据源代理方法
tableview
这时候数组明显是没有jid对象的。获取jid对象是在XMPPPRoster代理方法中实现的:
pragma mark xmppRoster 的代理方法
pragma mark 开始检索好友列表的方法-(void)xmppRosterDidBeginPopulating:(XMPPRoster *)sender{ NSLog(@"开始检索好友列表");}
pragma mark 正在检索好友列表的方法-(void)xmppRoster:(XMPPRoster )sender didRecieveRosterItem:(DDXMLElement )item{ NSLog(@"每一个好友都会走一次这个方法");//获得item的属性里的jid字符串,再通过它获得jid对象 NSString jidStr = [[item attributeForName:@"jid"] stringValue]; XMPPJID jid = [XMPPJID jidWithString:jidStr];//是否已经添加 if ([self.rosterJids containsObject:jid]) { return; }//将好友添加到数组中去 [self.rosterJids addObject:jid];//添加完数据要更新UI(表视图更新) NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.rosterJids.count-1 inSection:0]; [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:];}
pragma mark 好友列表检索完毕的方法-(void)xmppRosterDidEndPopulating:(XMPPRoster )sender{ NSLog(@"好友列表检索完毕");}
4. 删除好友。列表删除,数组删除,服务器删除。
pragma mark 删除好友执行的方法-(void)tableView:(UITableView )tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath )indexPath{ if (editingStyle==) { //找到要删除的人 XMPPJID jid = self.rosterJids[indexPath.row];//从数组中删除 [self.rosterJids removeObjectAtIndex:indexPath.row];//从Ui单元格删除 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation: ];//从服务器删除 [[XMPPManager defaultManager].xmppRoster removeUser:jid]; }}
5.进入聊天页面
5. ios怎么在xmpp自带的数据库中修改一条消息
主要用的类有:Roster 可以理解为好友花名册,提供创建删除获取列表等功能Roster.SubscriptionMode 这个在建立链接的时候使用,我的理解就是设置接收请求的模式,有三种,我们项目用的是SubscriptionMode.manual 也就是手动处理。Presence 有关好友的推送消息,都是Presence包Presence.Type 有7个Type,包含了好友上线下线、添加删除好友及错误信息的TypePacketFilter 过滤器,此功能中主要实现过滤出PresencePacketListener 看名字就知道,Packet监听,可以监听到服务端发来的所有信息。因为xmpp发的包都是它的子类~
6. ios xmppframework怎么传输文件
1 socks5 bytestreams 对应的协议是XEP-0065
2 In-Band Bytestreams(ibb) 对应的协议是XEP-0047
socks5 Bytestreams方法的优点是效率高,但是跨网段传输时需要一个文件代理。像openfire服务器就自带有文件代理,所以这个容易实现。
同网段传输可以直接连接,一般的实现是发起端建一个socks5服务。实际使用该方法时还需要使用XEP-0095协议来初始化流。XMPPFramework
未包含XEP-0095这个协议的实现,需要自己定义。
In-Band Bytestreams的优点是实现简单,但是效率不高。XMPPFramework也没有包含XEP-0047协议的实现。
还有另一个更高级的方法 -- Jingle,相关的协议是XEP-0166。该方法是google发明并公布的。该方法目前还未普及,XMPPFramework也没有
包含相应的实现,这是个很大的协议,实现起来应该很有难度。
如果使用XMPPFramework进行开发,那么对于文件传输最容易实现的方法应该是sock5 Bytestreams。
实现的时候主要就是认真看XEP-0095和XEP-0065这个两个协议文档
7. iOS怎么搭建xmpp聊天
iOS 搭建xmpp聊天的具体步骤如下:
聊天室
[cpp] view plain
print?
//初始化聊天室
XMPPJID *roomJID = [XMPPJID jidWithString:ROOM_JID];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self jid:roomJID];
[xmppRoom activate:xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[cpp] view plain
print?
//创建聊天室成功
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
{
DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);
}
[cpp] view plain
print?
//加入聊天室,使用昵称
[xmppRoom joinRoomUsingNickname:@"quack" history:nil];
[cpp] view plain
print?
//获取聊天室信息
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
{
[xmppRoom fetchConfigurationForm];
[xmppRoom fetchBanList];
[xmppRoom fetchMembersList];
[xmppRoom fetchModeratorsList];
}
如果房间存在,会调用委托
[cpp] view plain
print?
// 收到禁止名单列表
- (void)xmppRoom:(XMPPRoom *)sender didFetchBanList:(NSArray *)items;
// 收到好友名单列表
- (void)xmppRoom:(XMPPRoom *)sender didFetchMembersList:(NSArray *)items;
// 收到主持人名单列表
- (void)xmppRoom:(XMPPRoom *)sender didFetchModeratorsList:(NSArray *)items;
房间不存在,调用委托
[cpp] view plain
print?
- (void)xmppRoom:(XMPPRoom *)sender didNotFetchBanList:(XMPPIQ *)iqError;
- (void)xmppRoom:(XMPPRoom *)sender didNotFetchMembersList:(XMPPIQ *)iqError;
- (void)xmppRoom:(XMPPRoom *)sender didNotFetchModeratorsList:(XMPPIQ *)iqError;
离开房间
[cpp] view plain
print?
[xmppRoom deactivate:xmppStream];
[cpp] view plain
print?
//离开聊天室
- (void)xmppRoomDidLeave:(XMPPRoom *)sender
{
DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
}
其他代理
[cpp] view plain
print?
//新人加入群聊
- (void)xmppRoom:(XMPPRoom *)sender occupantDidJoin:(XMPPJID *)occupantJID
{
DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
}
//有人退出群聊
- (void)xmppRoom:(XMPPRoom *)sender occupantDidLeave:(XMPPJID *)occupantJID
{
DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
}
//有人在群里发言
- (void)xmppRoom:(XMPPRoom *)sender didReceiveMessage:(XMPPMessage *)message fromOccupant:(XMPPJID *)occupantJID
{
DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
}
8. iOS XMPP怎么实现语音聊天
前提条件
另外必须了解一些CoreData相关知识;
聊天设置原理
在init初始化时:发送普通文本消息同样在XMPPManager中进行封装;
9. Ios---XMPP聊天open Fire配置的127.0.0.1可以运行在真机上吗
同一个局域网即可。要配置一下,网上有。
将你的mac当成聊天的服务器。
10. 有哪位大哥知道基于XMPP的文件传输吗,有的话,请给一份用Smack API编写的文件传输的例子Java源代码
Spark是开源的基于XMPP用了的即时聊天软件,下载它的源代码,什么功能都有。
public void sendFile(final OutgoingFileTransfer transfer, FileTransferManager transferManager, final String jid, final String nickname) {
this.transferManager = transferManager;
cancelButton.setVisible(true);
retryButton.setVisible(false);
this.fullJID = jid;
this.nickname = nickname;
this.transfer = transfer;
String fileName = transfer.getFileName();
long fileSize = transfer.getFileSize();
ByteFormat format = new ByteFormat();
String text = format.format(fileSize);
fileToSend = new File(transfer.getFilePath());
imageLabel.setFile(fileToSend);
fileLabel.setText(fileName + " (" + text + ")");
ContactList contactList = SparkManager.getWorkspace().getContactList();
ContactItem contactItem = contactList.getContactItemByJID(jid);
titleLabel.setText(Res.getString("message.transfer.waiting.on.user", contactItem.getDisplayName()));
if (isImage(fileName)) {
try {
URL imageURL = new File(transfer.getFilePath()).toURI().toURL();
ImageIcon image = new ImageIcon(imageURL);
image = GraphicUtils.scaleImageIcon(image, 64, 64);
imageLabel.setIcon(image);
}
catch (MalformedURLException e) {
Log.error("Could not locate image.", e);
imageLabel.setIcon(SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32));
}
}
else {
File file = new File(transfer.getFilePath());
Icon icon = GraphicUtils.getIcon(file);
imageLabel.setIcon(icon);
}
cancelButton.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent mouseEvent) {
transfer.cancel();
}
});