gpt4 book ai didi

ios - 如何在我的网络服务中显示加载 View Controller

转载 作者:行者123 更新时间:2023-12-01 17:40:54 24 4
gpt4 key购买 nike

我想在调用 loginUserintoserver 方法时显示加载 View Controller 或事件指示器 View ,但在调试时我发现该 View 在这一行变得不活动。

 NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil]; 

有一段时间,直到我得到回应。我曾尝试显示事件指标,但没有成功。请任何指导方针来解决这个问题。提前致谢。
-(void) loginUserintoserver

{
NSString *str_validateURL = @"callogin";

//em,password,devicereg,devicetype,flag = ("e"or "m")
NSString *str_completeURL = [NSString stringWithFormat:@"%@%@", str_global_domain, str_validateURL];
NSURL *url = [NSURL URLWithString:str_completeURL];


NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];

[theRequest setHTTPMethod:@"POST"];

[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

str_global_UserPhone = [NSString stringWithFormat:@"%@%@",signupCountryCodeTextField.text,signupMobileTextField.text];

NSString *postData = [NSString stringWithFormat:@"em=%@&password=%@&devicereg=%@&devicetype=%@&flag=%@", loginEmailTextField.text, loginPasswordTextField.text, str_global_DeviceRegID, @"1", [NSString stringWithFormat:@"%@", emailphoneFlag]];

NSLog(@"==============%@",postData);
NSString *length = [NSString stringWithFormat:@"%d", [postData length]];

[theRequest setValue:length forHTTPHeaderField:@"Content-Length"];

[theRequest setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]];

// here the view becomes inactive and takes time to get response from server

NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
NSLog(@"response data is %@", responseData);

if (responseData == nil)
{
NSLog(@"No data from server");

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"No data downloaded from server!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertView show];

}
else
{
NSLog(@"response data is %@", responseData);
NSString *returnString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"returnString....%@",returnString);

NSDictionary *response_dic = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];

NSString *msg;
msg = [response_dic objectForKey:@"Result"];
NSDictionary *loginDict=[[NSDictionary alloc]init];
loginDict=[response_dic objectForKey:@"Result"];
NSLog(@"msg is : %@ ",[response_dic objectForKey:@"Result"]);

if ([[[response_dic objectForKey:@"Result"] objectForKey:@"ErrorCode"] isEqualToString:@"0"])
{
// success
NSLog(@"Successfull Login!!!!!");

NSString *UserId=[loginDict objectForKey:@"userid"];
[[NSUserDefaults standardUserDefaults] setValue:UserId forKey:@"LoginId"];

[self initRevealViewController];


} else if ([[[response_dic objectForKey:@"Result"] objectForKey:@"ErrorCode"] isEqualToString:@"1"]){
NSLog(@"Invalid Password!");

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message: @"ReEnter Password" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];


}else if ([[[response_dic objectForKey:@"Result"] objectForKey:@"ErrorCode"] isEqualToString:@"3"]){
NSLog(@"Invalid input parameters!");

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message: @"Email address or Mobile number, Password, devicereg, devicetype, flag are Mandatory" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];


}else if ([[[response_dic objectForKey:@"Result"] objectForKey:@"ErrorCode"] isEqualToString:@"6"]){
NSLog(@"Invalid input parameters!");

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message: @"User Registered but not activated" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];

}
}
}

最佳答案

你必须使用这个:MBProgressHUD

从上面的链接导入框架并做一些事情,比如:

.h 文件:

   #import "MBProgressHUD.h"

MBProgressHUD *HUD;

.m 文件执行此操作:
      HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];

[HUD show:YES];
// call your webservice here

[HUD hide:YES];

可能会有所帮助。

快乐编码... :)

关于ios - 如何在我的网络服务中显示加载 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20139428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com