我正在开发XMPP项目。我创建了连接并能够成功登录。但是我已经在appdelegate [connect]方法中设置了所有方法。所以当我登录成功的应用程序,但是当我必须获取朋友列表,然后我不得不再次调用appdelegate [connect]方法,所以我想设置所有条件和所有viewcontroller Loginbutton。所以当第二次调用appdelegate [connect]方法时,它不会影响到其他视图控制器,也会导致结果。我已经尝试了声明BOOL方法,但我不成功。 这里是我的尝试。ios xmpp通过appdelegate从一个视图控制器调用另一个视图控制器
//appdelegate.m file//
-(BOOL) isauthenticate; // Mthod declaration
- (BOOL)connect
{
// HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES] ;
//HUD.delegate = self;
HUD = [[MBProgressHUD alloc ] initWithWindow:[UIApplication sharedApplication ].keyWindow]; [self.window.rootViewController.view addSubview:HUD];
[HUD setDetailsLabelText:@"Please wait..."];
[HUD setDimBackground:YES];
[HUD setOpacity:0.5f];
[HUD show:YES];
// HUD.color =[UIColor colorWithPatternImage:[UIImage imageNamed:@"logo"]];
// [HUD hide:YES afterDelay:10.0];
if (![xmppStream isDisconnected]) {
return YES;
// isauthenticate=YES;
}
NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyJID];
NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyPassword];
//
// If you don't want to use the Settings view to set the JID,
// uncomment the section below to hard code a JID and password.
//
// myJID = @"[email protected]/xmppframework";
// myPassword = @"";
if (myJID == nil || myPassword == nil) {
return NO;
}
[xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
password = myPassword;
NSError *error = nil;
if (![xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error])
{
HUD.hidden=YES;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error connecting"
message:@"See console for error details."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
// DDLogError(@"Error connecting: %@", error);
// return NO;
}
return YES;
}
这里是我的Viewcontroller.m文件
//viewcontroller.m file//
- (IBAction)checkLogin:(id)sender {
[self dismissKeyboard];
// HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES] ;
// HUD.delegate = self;
NSLog(@"Email: %@ Password: %@",mViewEmail.text,mViewPassword.text);
[self setField:mViewEmail forKey:kXMPPmyJID];
[self setField:mViewPassword forKey:kXMPPmyPassword];
if ([[self appDelegate ]connect])
{
if (appdelegate.isauthenticate==YES) {
//appdelegate.isauthenticate=YES;
[self showHome];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry"
message:@"Please Check Username or Password"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
}
- (void)showHome{
//[[self appDelegate]isauthenticate];
[self performSegueWithIdentifier:@"signIn" sender:self];
}
究竟是什么解决办法吗?
那么我该如何在buddlist控制器中设置?目前我正在使用此条件来查看朋友列表。如果([[self appDelegate] connect]){ titleLabel.text = [[[[self appDelegate] xmppStream] myJID] bare]; } else { titleLabel.text = @“No JID”; } [titleLabel sizeToFit]; self.navigationItem.titleView = titleLabel; ' –
其实你正在检查你的身份验证与jid和pwd是否经过身份验证。你不是在管理好友列表。 –
是的,你是对的,但是当我使用这个条件时,它会再次调用connect方法,我的页面会再次被重定向到home.because connectiondidauthenticate再次执行。所以,我只想在登录按钮中实现segue。 –