Wes*_*ley 1 iphone xcode objective-c asihttprequest ios
这可能是一个简单的问题,但我现在已经盯着这一段时间,我找不到它!
我有一个SOAPRequest类,如下所示:
@interface SoapRequest : NSObject
@property (retain, nonatomic) NSURL *endPoint;
@property (retain, nonatomic) NSString *soapAction;
@property (retain, nonatomic) NSString *userName;
@property (retain, nonatomic) NSString *passWord;
@property (retain, nonatomic) NSString *postData;
@property (retain, nonatomic) NSObject *handler;
@property SEL action;
+ (SoapRequest*) create: (NSObject*) target endPoint: (NSString*) endPoint action: (SEL) action soapAction: (NSString*) soapAction postData: (NSString*) postData;
- (id)sendSynchronous;
- (void) send;
@end
Run Code Online (Sandbox Code Playgroud)
实施如下:
@synthesize endPoint = _endPoint, soapAction = _soapAction, userName = _userName, passWord = _passWord, postData = _postData, action = _action, handler = _handler;
+ (SoapRequest*) create: (NSObject*) target endPoint: (NSString*) endPoint action: (SEL) action soapAction: (NSString*) soapAction postData: (NSString*) postData
{
SoapRequest *request = [[SoapRequest alloc] init];
request.endPoint = [NSURL URLWithString:endPoint];
request.soapAction = soapAction;
request.handler = target;
request.action = action;
request.postData = postData;
return [request autorelease];
}
Run Code Online (Sandbox Code Playgroud)
我的发送功能:
- (void) send
{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:self.endPoint];
[request setDelegate:self];
[request addRequestHeader:@"Content-Length" value: [NSString stringWithFormat:@"%d",[self.postData length]]];
[request addRequestHeader:@"Content-Type" value:@"text/xml"];
if(self.soapAction)
{
[request addRequestHeader:@"soapAction" value:self.soapAction];
}
[request appendPostData:[self.postData dataUsingEncoding:NSUTF8StringEncoding]];
[request startAsynchronous];
}
Run Code Online (Sandbox Code Playgroud)
我确实有默认的ASIHTTPRequest方法来监听错误或完成,我的完成看起来如下:
- (void)requestFinished:(ASIHTTPRequest *)request
{
[self.handler performSelector:self.action];
}
Run Code Online (Sandbox Code Playgroud)
情况是,当我想让这个类成为ASIHTTPRequest的委托时,它会崩溃,[请求setDelegate:self].我认为它与第一个函数中的Autoreleasing有关.但我不知道如何解决它!
编辑:
这是我初始化SoapRequest的方式:
- (SoapRequest*) DefinedEntities: (id) _target action: (SEL) _action
{
// some data inits
SoapRequest *request = [SoapRequest create: _target endPoint:endPoint action:_action soapAction:soapAction postData:xmlString];
[request send];
return request;
}
Run Code Online (Sandbox Code Playgroud)
这我初衷如下:
Metadata *service = [[Metadata alloc] init];
[service DefinedEntities:self action:@selector(MetadataFinished:)];
Run Code Online (Sandbox Code Playgroud)
小智 5
有像你这样的问题.问题是,它在调用委托方法之前被释放.只需retain在启动方法和release完成的方法中添加一个(并且不要忘记在错误方法中释放它).只要请求正在执行,这将使对象处于生命中.
| 归档时间: |
|
| 查看次数: |
1065 次 |
| 最近记录: |