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