我使用带有ARC的Xcode 4.2.1
我尝试使用异步请求来肥皂网服务。我有2个类名称Connector和EmergencyCall。 EmergencyCall是Connector的代表。
这是Connector.h
@protocol ConnectorDelegate;
@interface Connector : NSObject
@property (retain,nonatomic) NSMutableData *webData;
@property (retain,nonatomic) NSString *theXML;
@property (nonatomic,assign) id<ConnectorDelegate> delegate;
@property (nonatomic,retain) NSString *theURL;
-(void)callWebServiceWithSoapBody:(NSString *)soapBody;
-(id)initWithURL:(NSString *)url;
+(id)ConnectorWithURL:(NSString *)url;
@end
@protocol ConnectorDelegate <NSObject>
-(void)callDidFinish:(Connector *)controller;
@end
在Connector.m中的我使用带有异步请求的NSURLConnection
NSURLConnection * theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
三种连接方法
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"Cannot Connect");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",theXML);
[self.delegate callDidFinish:self]; <<<<< error SIGABRT and EXC_BAD_ACCES
}
我可以连接到Web服务并在XML中获得响应。我试图将XML发送到EmergencyCall类以从xML解析为objective-c对象,但是我收到错误SIGABRT和EXC_BAD_ACCES。我想那是因为我在
中设置了另一个委托NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
现在我不知道如何将Connector类中的XML发送到EmergencyCall类。
我尝试连接同步请求的另一种方式
NSURLResponse *response = nil;
NSError *error = nil;
NSData thewebData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:response error:error];<<< the Xcode say autorelease diallowed in ARC
Xcode说NSURLResponse和NSData自动释放在ARC中拨号
所以我用-fno-objc-arc标记了这个Connector类,但仍然出现错误。
我不知道该怎么办? 拜托,有人建议我。