ios xmpp 通过 appdelegate 从 oneview 控制器调用另一个 viewcontroller

ios xmpp call another viewcontroller from oneview controller through appdelegate

我正在做 XMPP 项目。我已经创建了连接并能够登录 successfully.but 我有设置方法,并且都在 appdelegate [connect] 方法中。所以当我成功登录应用程序但当我必须获取好友列表时,我必须再次调用 appdelegate [connect] 方法所以我想设置所有条件并全部在 viewcontroller 登录按钮中。因此,当第二次 appdelegate [connect] 方法调用时,它不会影响其他视图控制器,也不会产生结果。我已经尝试过声明 BOOL 方法,但我没有成功。 这是我的尝试。

//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 = @"user@gmail.com/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];
            }

解决这个问题的方法是什么?

1) 不终止 xmpp 会话。

2) 如果你有活动的 xmpp 会话,则不需要调用应用程序委托的连接方法。

3) 如果您的会话已过期,则调用连接方法。

4) 要检索好友列表,必须使用 iOS XMPP 客户端在 xmpp 服务器上管理花名册。

5) 您可以通过调用 XMPPRoster class 的 getAllRoster 方法获取您的花名册列表,否则您可以在 class.

中实现 XMPP 花名册协议