所以我有一个具有以下界面的课程:
#import <UIKit/UIKit.h>
#import "XMPPStream.h"
@interface SignInViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *UserNameTextField;
@property (strong, nonatomic) IBOutlet UITextField *PassWordTextField;
@property (strong, nonatomic) XMPPStream *myStream;
- (IBAction)SignInButtonPress:(UIButton *)sender;
@end
然后,如果评估SignInButtonPress
方法,我有这个代码:
- (IBAction)SignInButtonPress:(UIButton *)sender {
self.myStream = [[XMPPStream alloc]init];
[self.myStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
NSString *jid = self.UserNameTextField.text;
jid = [jid stringByReplacingOccurrencesOfString:@"@" withString:@"(at)"];
self.myStream.myJID = [XMPPJID jidWithString:self.UserNameTextField.text];
//stream.jid = self.UserNameTextField.text;
self.myStream.hostName = @"myAWSDNS.us-west-2.compute.amazonaws.com";
NSError *error = [[NSError alloc]init];
if ([self.myStream connectWithTimeout:0 error:&error] == YES)
{
NSLog(@"DId Connect!");
//[self performSegueWithIdentifier:@"Move" sender:sender];
}
else
{
NSLog(@"ou");
}
}
self.myStream connectWithTimeout
似乎运行正常,调用后错误为nil
,我在日志中收到“Did Connect”。
然而,即使我将self添加为xmppStream
的委托(参见方法的开头),委托方法
-(void) xmppStreamDidConnect:(XMPPStream *)sender
不会被调用,即使我在同一个类中实现它:
-(void) xmppStreamDidConnect:(XMPPStream *)sender
{
if ([sender authenticateWithPassword:self.PassWordTextField.text error:NULL] ==YES)
{
NSLog(@"authed!");
[self performSegueWithIdentifier:@"move" sender:sender];
}
else
{
}
}
为什么没有调用该方法,我该如何排除故障和/或解决此问题?
答案 0 :(得分:1)
当我使用Swift的XMPP框架时,我不确定这是否对您有所帮助。为了让它在我的应用程序中运行,我必须确保实现 XMPPStreamDelegate 协议以及从 NSObject 继承(当你从继承时给出) UIViewController)就像这样:
<强>夫特:强>
class SignInViewController: UIViewController, XMPPStreamDelegate
<强>目标C 强>
@interface SignInViewController : UIViewController <XMPPStreamDelegate>