我在这里看到了类似的问题,但我无法找到解决问题的方法.我在主线程中有一个简单的NSURLConnection(至少我没有创建任何其他线程),但是我的委托方法没有被调用
[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
Run Code Online (Sandbox Code Playgroud)
并且没有被称为的方法,例如
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"didReceiveResponse");
}
Run Code Online (Sandbox Code Playgroud)
self也是NSXMLParser的委托,但我认为它不应该是一个问题,因为我在同一个项目中的其他类中工作.我已经检查了10次,但找不到任何问题.
我在这里看到了一些黑客来解决它:http://www.depl0y.com/? p = 345 但我不喜欢它,可能有人知道更好的解决方案吗?谢谢
我有一个名为calls的类BackendConnector,它使用a NSURLConnection来调用SoapWebservicehttps.我找到了很多帖子,并尝试实施代理方法有关身份验证,但他们不会被调用,在谷歌6小时后,我没有得到我做错了.有人可以给我一个提示,为什么这两个代表方法不会被调用?我在每个设置了一个断点,在模拟器中使用XCode启动了我的应用程序,但仍然得到错误并且断点没有被击中.
BackendConnector.m
#import "BackendConnector.h"
@implementation BackendConnector
@synthesize dataPoint, chartDataPoints;
- (NSMutableArray *)GetWebserviceData
{
NSMutableData *myMutableData;
chartDataPoints = [[NSMutableArray alloc] init];
[self createWebserviceAndGetResponse: &myMutableData];
if (myMutableData != NULL)
{
NSString *theXml = [[NSString alloc]initWithBytes:[myMutableData mutableBytes] length:[myMutableData length] encoding:NSUTF8StringEncoding];
NSLog(@"doc = %@", theXml);
arrayCount = 0;
[self parseResponse: myMutableData];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"There is no Data returned from Webservice!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
return NULL; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用NSURLConnection的委托方法.目前尚未调用以下方法:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
//I also want to be able to use self-signed https urls
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace;
//I also want to be able to use self-signed https urls
Run Code Online (Sandbox Code Playgroud)
我目前正在使用同步调用,但异步似乎更好,因为在我完成代码库后,我将把它实现到iPhone应用程序中,我不能让我的ui冻结.
用以下方法responseData = [NSMutableData dataWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]];
我得到了我需要的数据但是使用异步我似乎必须使用委托方法来获取数据.我尝试使用添加委托@interface myClass : NSObject<NSURLConnectionDelegate>
我正在调用我的方法如下:
-(void)grabData{
NSArray* array = [NSArray arrayWithObjects:@"auth.login",@"user",@"pass", nil];
NSData* packed_array = [array messagePack];
NSURL* url = [NSURL URLWithString:@"https://192.168.1.115:3790/"];
NSMutableURLRequest* request = [[[NSMutableURLRequest alloc]initWithURL:url]retain];
[request setHTTPMethod:@"POST"]; …Run Code Online (Sandbox Code Playgroud)