到這裡、 我們封裝了XMPP 登錄、 注冊、 好友列表獲取、 好友狀態獲取、 信息的收發、
應該去測試一下了 、 我這裡把最簡單的測試辦法扔到這裡、 大家可以看一下 。
// // ADViewController.m // ADXMPP_BE // // Created by Dylan on 14-10-8. // Copyright (c) 2014年 Dylan. All rights reserved. // #import "ADViewController.h" #import "ADMessageModel.h" @interface ADViewController () @end @implementation ADViewController - (void)viewDidLoad { [super viewDidLoad]; // testLogin [XMPPHANDLE connectionWithUserName:@"[email protected]" passWord:@"admin" success:^{ NSLog(@"success"); [XMPPHANDLE refreshRosterPresence:^(NSString * userID) { NSLog(@"%@%@", userID, DOMAINS); } offline:^(NSString * userID) { NSLog(@"%@%@", userID, DOMAINS); }]; [XMPPHANDLE refreshRosterList:^(id dict) { NSLog(@"%@", dict); } failure:^(id error) { NSLog(@"%@", error); }]; // testMsg [[NSUserDefaults standardUserDefaults] setValue:@"[email protected]/xueyulundeMacBook-Pro" forKey:CURRENT_CHAT]; [XMPPHANDLE setNewMessage:^(id dict) { NSLog(@"%@", dict); }]; ADMessageModel * model = [[ADMessageModel alloc] init]; model.from = [NSString stringWithFormat:@"%@", XMPPHANDLE.xmppStream.myJID]; model.to = [[NSUserDefaults standardUserDefaults] stringForKey:CURRENT_CHAT]; model.body = @"Hello"; [XMPPHANDLE sendMessage:model sendSuccess:^{ NSLog(@"send success"); } sendFailure:^(id error) { NSLog(@"%@", error); }]; } failure:^(id error) { NSLog(@"error"); }]; // testRegis // [XMPPHANDLE registerWithUserName:@"test" passWord:@"admin" success:^{ // NSLog(@"register success"); // } failure:^(id error) { // NSLog(@"%@", error); // }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end
特別需要注意的是代碼的執行先後順序。
代理執行方法的先後順序
保證自己的Block方法體可以被尋找到