【问题标题】:ios xmpp call another viewcontroller from oneview controller through appdelegateios xmpp通过appdelegate从oneview控制器调用另一个viewcontroller
【发布时间】:2015-06-01 08:01:54
【问题描述】:

我正在从事 XMPP 项目。我已经创建了连接并且能够成功登录。但是我有设置方法并且全部在 appdelegate [connect] 方法中。所以当我成功登录应用程序但当我必须获取朋友列表时,我必须再次调用 appdelegate [connect] 方法,所以我想在 viewcontroller Loginbutton 中设置所有条件。因此,当第二次 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];
            }

解决办法是什么?

【问题讨论】:

    标签: ios methods xmpp


    【解决方案1】:

    1) 不要终止 xmpp 会话。

    2) 如果您有活动的 xmpp 会话,则无需调用应用委托的连接方法。

    3) 如果您的会话过期而不是调用连接方法。

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

    5) 您可以通过调用 XMPPRoster 类的 getAllRoster 方法获取您的花名册列表,否则您可以在您的类中实现 XMPP Roster 协议。

    【讨论】:

    • 那么我如何在 buddlist 控制器中设置它?目前我正在使用这个 if 条件来查看朋友列表。 ' if ([[self appDelegate] connect]){ titleLabel.text = [[[[self appDelegate] xmppStream] myJID] bare]; } else { titleLabel.text = @"No JID"; } [titleLabel sizeToFit]; self.navigationItem.titleView = 标题标签; '
    • 实际上,您正在使用 jid 和 pwd 检查您的身份验证是否已通过身份验证。你没有管理好友列表。
    • 是的,您是对的,但是当我使用此条件时,它将再次调用 connect 方法,并且我的页面将再次重定向到主页。因为 connectiondidauthenticate 再次执行。所以,我只想在登录按钮中实现 segue。
    • 不要使用您的方法,只需将 xmppStream 类的方法调用为 [xmppStream isConnected] 即可验证您的活动会话。如果您未通过身份验证,则转到身份验证过程,否则转到下一个屏幕
    • 谢谢兄弟,我能理解一点点。我是 XMPP 的新手。如果您有任何文档或虚拟源代码,请上传或参考我的链接。我已经检查了聊天的安全性,但它对我来说很容易理解。再次感谢。
    猜你喜欢
    • 2012-05-10
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多