0
AFNetworking을 사용 중이며 코드는 정상적으로 작동하지만 NSURLConnectionDelegate 메서드의 대리자 메서드 중 아무 것도 성공적으로 연결 한 후에 호출되지 않습니다.NSURLConnectionDelegate 메서드가 AFNetworking 코드를 사용하여 호출되지 않았습니다.
NSURLConnection의 위임자로 내 인터페이스 파일에서 선언했습니다.하지만 아무 것도 작동하지 않는 것 같습니다. 백그라운드 스레드 및 기본 스레드로 작업 할 때 문제가 있습니까?
NSLog(@"\n\n1 Is main thread %@", ([NSThread isMainThread] ? @"Yes" : @" NOT"));
AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes= [NSSet setWithObject:@"text/html"];
NSDictionary *parameters = @{
@"email": [Constants sharedInstance].email,
@"password": [Constants sharedInstance].password,
};
NSLog(@"\n\nparameters: %@",parameters);
[manager POST:@"https://anyurl/" parameters:parameters success:^
(AFHTTPRequestOperation *operation, id responseObject) {
// [operation setRunLoopModes:[NSSet setWithObject:NSDefaultRunLoopMode]];
NSLog(@"\n\n 2 Is main thread %@", ([NSThread isMainThread] ? @"Yes" : @" NOT"));
[self stopLoading];
NSLog(@"\n\nconnection successful!!");
NSLog(@"\n\nJSON: %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"\n\nError: %@", error);
[self stopLoading];
NSLog(@"Connection could not be made");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Network" message:@"Cannot make connection to the server" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
];
NSLog(@"\n\n 3 Is main thread %@", ([NSThread isMainThread] ? @"Yes" : @" NOT"));
[self startLoading];
NSLog(@"\n\n4 Is main thread %@", ([NSThread isMainThread] ? @"Yes" : @" NOT"));
나는 그 대답을 사용할 수이
link하지만 보았다 : 다음은 내 코드입니다.
thanx 대신
NSURLConnection
을 사용하십시오. 그러나 성공적인 연결에서 didRecieveData와 같은 함수를 호출하려면 어떻게 호출해야합니까? – SandeepAggarwal또한 이러한 모든 관련 게시물이 어떻게 유효합니까? http://stackoverflow.com/q/14836948/3632958 http://stackoverflow.com/q/20143951/3632958 – SandeepAggarwal