1
votes

I'm writing a little static library (lib.a) for the iphone and I'm using ASIHTTPRequest to manage my data posting and etc.

I have the main implementation (@implementation BlaBla) but in the main .m file, I have another (@interface Foo) and (@implementation Foo) for private methods.

I've implemented the ASIHTTPRequestDelegate in the (@interface Foo) but the - (void)requestFinished:(ASIHTTPRequest *)request, but this method doesn't executing!

No matter what I did, it doesn't work. I've added NSLog to log the requestFinished method, but it's not working.

Example code:

@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

I'll be very thankful for any help!

BTW, can it be because of instance methods (-) or class methods (+)?

2

2 Answers

1
votes

You calling self from a Class Method, your code should like this:

@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
0
votes

Shouldn't it be:

  BlaRequest.delegate = self;

Instead of:

  self = [BlaRequest delegate];