Before iOS5 I could test to see what URL I was getting a response from my code looked like this:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
returnString = [[[NSMutableString alloc] initWithData:responseData encoding: NSUTF8StringEncoding] autorelease];
NSString * currentParseString = [NSString stringWithFormat:@"%@",connection];
NSLog(@"Currently Parsing: %@",currentParseString);
}
my log would print out "Currently Parsing: http://www.myinfo.com/parser....
"
Which I could then use to test and send into different IF statements. My problem now is, in iOS5 the connection
is no longer printing as a URL, it is printing as a block of memory <NSURLConnection: 0x6a6b6c0>
How could I get it to print out as a URL again so I dont have to rewrite my IF statements?
I did something like this :
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"%@",[connection currentRequest]);
}
When you put %@
within a NSString
format it will be replaced by [object description]
. Apple must have changed what [connection description]
returns. It's hard to rely on that in any case as it's not guaranteed to be in any particular format.
There are a number of ways you could change your implementation. Probably the quickest is to create a very simple subclass of NSURLConnection
along the lines of:
// MyNSURLConnection.h
// code written assuming ARC
@interface MyNSURLConnection : NSURLConnection
@property (nonatomic, strong) NSURL *requestURL;
@end
// MyNSURLConnection.m
// example override, you can override all the init/connection methods
- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate startImmediately:(BOOL)startImmediately {
self = [super initWithRequest:request delegate:delegate startImmediately:startImmediately;
if (self) {
self.requestURL = request.URL;
}
return self;
}
// in your MyNSURLConnectionDelegate controller
- (void)connectionDidFinishLoading:(MyNSURLConnection *)connection {
returnString = [[[NSMutableString alloc] initWithData:responseData encoding: NSUTF8StringEncoding] autorelease];
NSString * currentParseString = [NSString stringWithFormat:@"%@",connection.requestURL];
NSLog(@"Currently Parsing: %@",currentParseString);
// rest of your code
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With