I’m creating an instance of a class called S3ObjectController (S3OC) that has one method and four delegate methods. I create an instance of my S3OC, call an instance method from the S3OC Class (which I know fires from NSLog statements) but none of the associated delegate methods are called within the S3OC class. I have the delegate set to self in the method and the delegate declared properly in the .h header.
Thoughts? just to be clear, it’s the (void)request methods in the .m file below I’m thinking should be called that aren’t. I’m getting EXC BAD ACCESS errors. Is self getting released by ARC?
The entire .m file of the S3OC class is below:
#import "S3ObjectController.h"
@implementation S3ObjectController
@synthesize string;
@synthesize s3GOR, s3Client;
-(void)method
{
NSLog(@"Method Called");
s3Client = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
s3GOR = [[S3GetObjectRequest alloc]initWithKey:string withBucket:[Constants pictureBucket]];
[s3GOR setDelegate:self];
[s3Client getObject:s3GOR];
NSLog(@"Method Finished");
}
-(void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Error %@",error);
}
-(void)request:(AmazonServiceRequest *)request didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Response Key %@", response);
}
-(void)request:(AmazonServiceRequest *)request didReceiveData:(NSData *)data
{
NSLog(@"ObjectRequestKey = %@",request);
}
-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
{
NSLog(@"Final Delegate Method");
}
Here’s the header:”
@interface S3ObjectController : NSObject <AmazonServiceRequestDelegate>{
NSMutableData *responseData;
NSString *string;
AmazonS3Client *s3Client;
S3GetObjectRequest *s3GOR;
}
-(void)method;
@property (nonatomic, strong) NSString *string;
@property (nonatomic, strong) S3GetObjectRequest *s3GOR;
@property (nonatomic, strong) AmazonS3Client *s3Client;
@end
Finally, here’s how I call the method in another class:
for (NSString *name in nameArray){
@try {
S3ObjectController *localS3 = [[S3ObjectController alloc]init];
localS3.string = name;
[localS3 method];
NSLog(@"called");
}
I think your suspicions about ARC are true. Because delegate properties are usually weak references, they aren’t enough to keep the object from being released.
Make an NSArray that’s an iVar and add the S3ObjectController to it. If the delegates still don’t fire, you know it’s something else…
Edit:
so declare an NSMutableArray in the header of the class that contains your for loop, initialize it somewhere like this:
then use it like this: