Multithreading 未使用AFNetworking代码调用NSURLConnectionLegate方法
我使用的是AFNetworking,代码运行良好,但在成功连接后,没有调用NSURLConnectionLegate方法的任何代理nethods 我在我的接口文件中也声明了NSURLConnection的委托。但似乎什么都不起作用,使用后台线程和主线程有什么问题吗? 这是我的密码:Multithreading 未使用AFNetworking代码调用NSURLConnectionLegate方法,multithreading,ios7,afnetworking-2,nsurlconnectiondelegate,Multithreading,Ios7,Afnetworking 2,Nsurlconnectiondelegate,我使用的是AFNetworking,代码运行良好,但在成功连接后,没有调用NSURLConnectionLegate方法的任何代理nethods 我在我的接口文件中也声明了NSURLConnection的委托。但似乎什么都不起作用,使用后台线程和主线程有什么问题吗? 这是我的密码: NSLog(@"\n\n1 Is main thread %@", ([NSThread isMainThread] ? @"Yes" : @" NOT")); AFHTTPRequestOperationMana
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"));
我看到了这一点,但无法使用该答案。
AFNetworking
是一个单独的库,如果您使用AFNetworking
,它的成功和失败块将被执行。如果您想执行nsurlconnectionelegate
方法,请使用NSURLConnection
而不是AFNetwork
thanx获取信息,但我想在成功连接时调用direceivedata之类的函数,那么如何调用它们呢?为什么所有这些相关帖子都是有效的呢?