내 응용 프로그램에서 웹 서비스 (안심 웹 서비스)를 사용하고 있습니다. 사용자 인증을 위해 하나의 서비스를 사용하여 로그인하는 방법, 웹 서비스를 호출하는 IBAction이있는 UIButton이 있습니다. 여기에이 웹 서비스를 호출하는 메서드가 있습니다. :멀티 스레딩을 사용하여 iphone에 로그인 하시겠습니까?
-(void)LogInMethod{
NSString * password=passwordTextField.text;
NSString * mobileNumber=MobileTextField.text;
if (password.length==0 || mobileNumber.length==0) {
if (mobileNumber.length==0) {
[wrongNoteLable setText:@"please enter a valid mobile number"];
[wrongNoteLable setHidden:NO];
}
else if (password.length==0){
[wrongNoteLable setText:@"please enter a valid password"];
[wrongNoteLable setHidden:NO];
}
}
else{
NSString*UrlString=[[NSString alloc]initWithFormat:@"http://192.168.1.1:8080/test2/eattel/customers/signin/%@/123/%@",mobileNumber,password];
NSURL *url = [[NSURL alloc] initWithString:UrlString ];
NSError *error = nil;
NSStringEncoding encoding = 0;
customerID =[[NSString alloc]initWithContentsOfURL:url encoding:encoding error:&error];
if (customerID) {
if (![customerID isEqualToString: @"-1"]) {
[self performSegueWithIdentifier:@"toMainMenuViewController" sender:self];
NSLog(@"customer loged in with ID :%@",customerID);
}
else if ([customerID isEqualToString:@"-1"]){
[wrongNoteLable setText:@"neither mobile number or password is wrong"];
[wrongNoteLable setHidden:NO];
NSLog(@"customer tried to log in with wrong password or phone Number :%@",customerID);
}
}
else{
[wrongNoteLable setText:@"no connection to the server"];
[wrongNoteLable setHidden:NO];
NSLog(@"customer tried to log in but there is no server connection :%@",customerID);
}
}
// NSLog([dispatch_get_main_queue() description])
}
와 나는이 같은 IBAction를에 스레드를 사용하여 이전 메소드를 호출하는 것을 시도하고있다 :
- (IBAction)signInAction:(id)sender {
NSThread* myThread = [[NSThread alloc] initWithTarget:self
selector:@selector(LogInMethod)
object:nil];
[myThread start]; // Actually create the thread
}
하지만이 오류 데 :
,536,913을WebThreadLockFromAnyThread(bool), 0xa08cf60: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.
주의 : 코드와 웹 서비스 API는 로그인 작업에 전혀 적절하지 않습니다. 1. 로그인 및 비밀번호를 리소스의 * 경로 * 요소로 만드는 것은 좋지 않습니다. URI 경로는 없습니다. https에서도 암호화되므로 항상 일반 텍스트로 보내십시오. 2. POST 요청이 필요할 것입니다. 3. 원격 리소스를로드하는 데'initWithContentsOfURL'을 사용하지 마십시오. 대리자 방식을 사용하는 NSURLConnection 또는 NSURLSession을 사용하십시오. – CouchDeveloper