How to check which NSURLConnection url gives you an answer?

Before iOS5, I was able to check which URL I get from the 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 journal will print " Currently Parsing: http://www.myinfo.com/parser...."

Which I could then use to test and send to different IF statements. My problem is that in iOS5 it connectionno longer prints as a URL, it prints as a block of memory. <NSURLConnection: 0x6a6b6c0>How can I make it print a URL again, so I don’t need to rewrite IF statements?

+5
source share
2 answers

I did something like this:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
   NSLog(@"%@",[connection currentRequest]);
}
+7
source

%@ NSString, [object description]. Apple, , , [connection description]. , - .

. , NSURLConnection :

// 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
}
+5

All Articles