Objective c 未调用AsiHttpRequestFinished
我正在为iphone编写一个小静态库(lib.a),并使用AsittpRequest管理我的数据发布等 我有主实现(@implementation BlaBla),但在main.m文件中,我有另一个(@interface Foo)和(@implementation Foo)用于私有方法 我已经在(@interface Foo)中实现了ASIHTTPRequestDelegate,但是-(void)requestFinished:(ASIHTTPRequest*)请求没有执行 不管我做了什么,它都不起作用。我已经添加了NSLog来记录requestFinished方法,但它不起作用 示例代码:Objective c 未调用AsiHttpRequestFinished,objective-c,ios,asihttprequest,static-libraries,Objective C,Ios,Asihttprequest,Static Libraries,我正在为iphone编写一个小静态库(lib.a),并使用AsittpRequest管理我的数据发布等 我有主实现(@implementation BlaBla),但在main.m文件中,我有另一个(@interface Foo)和(@implementation Foo)用于私有方法 我已经在(@interface Foo)中实现了ASIHTTPRequestDelegate,但是-(void)requestFinished:(ASIHTTPRequest*)请求没有执行 不管我做了什么,它都
@interface ActionsManager : NSObject <ASIHTTPRequestDelegate>
+ (void)blabla;
@end
@implementation ActionsManager
+ (void)blabla{
NSURL *requestUrl = [NSURL URLWithString:[NSString stringWithFormat:@"Bla.com/bla"]];
BlaRequest = [[[ASIFormDataRequest alloc] initWithURL:requestUrl]autorelease];
self = [BlaRequest delegate];
[BlaRequest setPostValue:blabla forKey:@"bla"];
[BlaRequest setRequestMethod:@"POST"];
[BlaRequest startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request{
NSLog(@"request finished");
}
- (void)requestStarted:(ASIHTTPRequest *)request{
NSLog(@"request started");
}
@end
@implementation MainImplementation
- (id)init
{
self = [super init];
if (self) {
}
return self;
}
+ (void)bbb{
[ActionsManager blabla];
}
@end
@接口操作管理器:NSObject
+(无效)布拉布拉;
@结束
@实现操作管理器
+(无效)布拉布拉{
NSURL*requestUrl=[NSURL URLWithString:[NSString stringWithFormat:@“Bla.com/Bla”];
BlaRequest=[[ASIFormDataRequest alloc]initWithURL:requestUrl]自动删除];
self=[BlaRequest delegate];
[BlaRequest setPostValue:blabla-forKey:@“bla”];
[BlaRequest setRequestMethod:@“POST”];
[BlackstartSynchronous];
}
-(void)requestFinished:(ASIHTTPRequest*)请求{
NSLog(@“请求完成”);
}
-(void)requestStarted:(ASIHTTPRequest*)请求{
NSLog(@“请求已启动”);
}
@结束
@执行主要执行
-(id)init
{
self=[super init];
如果(自我){
}
回归自我;
}
+(无效)bbb{
[ActionsManager布拉布拉];
}
@结束
我将非常感谢任何帮助
顺便说一句,这可能是因为实例方法(-)或类方法(+)?不应该是:
BlaRequest.delegate = self;
而不是:
self = [BlaRequest delegate];
难道不是:
BlaRequest.delegate = self;
而不是:
self = [BlaRequest delegate];
从类方法调用self时,代码应如下所示:
@interface ActionsManager : NSObject <ASIHTTPRequestDelegate>
- (void)blabla;
@end
@implementation ActionsManager
- (void)blabla{
NSURL *requestUrl = [NSURL URLWithString:[NSString stringWithFormat:@"Bla.com/bla"]];
ASIFormDataRequest *blaRequest = [ASIFormDataRequest requestWithURL:requestUrl];
blaRequest.delegate = self;
[blaRequest setPostValue:@"blabla" forKey:@"bla"];
[blaRequest setRequestMethod:@"POST"];
[blaRequest startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request{
NSLog(@"request finished");
}
- (void)requestStarted:(ASIHTTPRequest *)request{
NSLog(@"request started");
}
@end
@implementation MainImplementation
- (id)init
{
self = [super init];
if (self) {
}
return self;
}
+ (ActionsManager *)bbb{
ActionsManager *a = [ActionsManager new];
[a blabla];
return [a autorelease];
}
@end
@接口操作管理器:NSObject
-(无效)布拉布拉;
@结束
@实现操作管理器
-(无效)布拉布拉{
NSURL*requestUrl=[NSURL URLWithString:[NSString stringWithFormat:@“Bla.com/Bla”];
ASIFormDataRequest*blaRequest=[AsiformDataRequestRequestWithURL:requestUrl];
blaRequest.delegate=self;
[blaRequest setPostValue:@“blabla”forKey:@“bla”];
[blaRequest setRequestMethod:@“POST”];
[BlackstartSynchronous];
}
-(void)requestFinished:(ASIHTTPRequest*)请求{
NSLog(@“请求完成”);
}
-(void)requestStarted:(ASIHTTPRequest*)请求{
NSLog(@“请求已启动”);
}
@结束
@执行主要执行
-(id)init
{
self=[super init];
如果(自我){
}
回归自我;
}
+(ActionsManager*)bbb{
ActionsManager*a=[ActionsManager新建];
[废话];
返回[自动释放];
}
@结束
如果从类方法调用self,代码应该如下所示:
@interface ActionsManager : NSObject <ASIHTTPRequestDelegate>
- (void)blabla;
@end
@implementation ActionsManager
- (void)blabla{
NSURL *requestUrl = [NSURL URLWithString:[NSString stringWithFormat:@"Bla.com/bla"]];
ASIFormDataRequest *blaRequest = [ASIFormDataRequest requestWithURL:requestUrl];
blaRequest.delegate = self;
[blaRequest setPostValue:@"blabla" forKey:@"bla"];
[blaRequest setRequestMethod:@"POST"];
[blaRequest startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request{
NSLog(@"request finished");
}
- (void)requestStarted:(ASIHTTPRequest *)request{
NSLog(@"request started");
}
@end
@implementation MainImplementation
- (id)init
{
self = [super init];
if (self) {
}
return self;
}
+ (ActionsManager *)bbb{
ActionsManager *a = [ActionsManager new];
[a blabla];
return [a autorelease];
}
@end
@接口操作管理器:NSObject
-(无效)布拉布拉;
@结束
@实现操作管理器
-(无效)布拉布拉{
NSURL*requestUrl=[NSURL URLWithString:[NSString stringWithFormat:@“Bla.com/Bla”];
ASIFormDataRequest*blaRequest=[AsiformDataRequestRequestWithURL:requestUrl];
blaRequest.delegate=self;
[blaRequest setPostValue:@“blabla”forKey:@“bla”];
[blaRequest setRequestMethod:@“POST”];
[BlackstartSynchronous];
}
-(void)requestFinished:(ASIHTTPRequest*)请求{
NSLog(@“请求完成”);
}
-(void)requestStarted:(ASIHTTPRequest*)请求{
NSLog(@“请求已启动”);
}
@结束
@执行主要执行
-(id)init
{
self=[super init];
如果(自我){
}
回归自我;
}
+(ActionsManager*)bbb{
ActionsManager*a=[ActionsManager新建];
[废话];
返回[自动释放];
}
@结束
好吧,但应该是这样。在我的代码中,我实际上使用了一个ASINetworkQueue
在那里,我可以定义失败和成功的响应方法。你有任何示例如何使用它吗?但是我认为这个方法也不会被调用。改变一点主题,ASIHTTPRequest
不再被支持。因此,如果您发现一个bug或一些奇怪的行为,您将得不到原始作者的支持(至少在正常情况下)。我建议您开始使用此MKNetworkKit
。它基于ASIHTTPRequest
和一些额外的优点。好吧,但应该是这样的。在我的代码中,我实际上使用了一个ASINetworkQueue
,在那里我可以定义失败和成功的响应方法。你有任何例子如何使用它吗?但是我认为这个方法也不会被调用。改变一点主题,ASIHTTPRequest
不再被支持。因此,如果您发现一个bug或一些奇怪的行为,您将得不到原始作者的支持(至少在正常情况下)。我建议您开始使用此MKNetworkKit
。它是基于ASIHTTPRequest
的,有一些额外的优点。因为请求失败,您没有实现-(void)requestFailed:(ASIHTTPRequest*)请求方法…因为请求失败,您没有实现-(void)requestFailed:(ASIHTTPRequest*)请求方法。。。