여기에서이 iOS 클라이언트를 다운로드했습니다 : https://github.com/robbiehanson/XMPPFramework/ 및 메시지를 보낼 수 있도록 코드를 추가하고 싶습니다. 에서로드 된 ChatViewController
이라는 새 클래스를 만들었습니다. 이 뷰 컨트롤러를 초기화 할 때, 나는 아래 매개 변수로 xmppstream
을 전달합니다오픈 파이어 및 iOS를 사용하여 메시지를 보낼 수 없습니다.
stream =[[self appDelegate]xmppStream];
ChatViewController *chat = [[ChatViewController alloc]initWithStream:stream jid:user.jid];
[self.navigationController pushViewController:chat animated:YES];
내가 그러나 나는에 클릭을 통해 메시지를 보낼 수 없습니다, 내가 RootViewController
에서 얻을 스트림을 사용하여 메시지를 보낼 수 initWithStream
체크 ChatViewController
의 버튼 내가 initWithStream
에 메시지를 전송하는 코드를 넣으면
#import "ChatViewController.h"
#import "XMPPFramework.h"
@interface ChatViewController()
@end
@implementation ChatViewController
@synthesize MyxmppStream;
@synthesize jid;
-(id)initWithStream:(XMPPStream *)stream jid:(XMPPJID *)ajid{
self = [super initWithNibName:@"ChatViewController" bundle:nil];
if (self) {
jid = ajid;
MyxmppStream = stream;
}
return self;
}
- (IBAction)SendMessage:(id)sender {
NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue:@"aaaa"];
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[jid full]];
[message addChild:body];
[MyxmppStream sendElement:message];
}
@end
, 그것은 잘 작동하고 성공적으로 메시지를 보낼 수 있지만 SendMessage
에서 동일한 코드는 전혀 작동하지 않습니다 ChatViewController
의 m 파일은 다음과 같습니다.
이 MyXmppStream 강하다? – vitalyster
예, ChatViewController.h에서 MyXmppStream을 다음과 같이 선언합니다. @property (비 원자력, 강함) XMPPStream * MyxmppStream; – Demonedge