【发布时间】: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];
}
解决办法是什么?
【问题讨论】: