views:

26

answers:

2

Hi all... my corporate overlords want me to display image ads for our upcoming iPad application. I'm currently trying to show the image by using the following code:

- (UIImage *)getAdImage:(NSString *)adName {

NSString *adID = [self getPrivateConfigSettings:adName];
NSString *adUrl =
     [NSString stringWithFormat:[self getPrivateConfigSettings:@"eplanningURL"],
     [self getPrivateConfigSettings:@"eplanningSite"], adID];

NSData *theData =
     [NSData dataWithContentsOfURL:[NSURL URLWithString:adUrl]];

return [UIImage imageWithData: theData];
}

As it stands, its throwing the following exception:

Terminating app due to uncaught exception 'NSRangeException', reason:
'*** -[NSCFArray objectAtIndex:]: index (-1( or possibly larger))
beyond bounds (0)'

in the line where I create "theData".

However, when I check the URL I'm loading (http://ads.us.e-planning.net/eb/3/9770/19e905cdc35ec591?o=i) it has data on it.

PD: I know that code is leaky! for now I just want to find the cause of my error ;)

+2  A: 

Try to manually set your URL, like this:

- (UIImage *)getAdImage:(NSString *)adName {

NSString *adUrl = @"http://ads.us.e-planning.net/eb/3/9770/19e905cdc35ec591?o=i";

NSData *theData =
     [NSData dataWithContentsOfURL:[NSURL URLWithString:adUrl]];

return [UIImage imageWithData: theData];
}

If it works fine, your problem is in retrieving the correct URL from the getPrivateConfigSettings.

notme