NSURLDownload with Authentication
NSURLDownload with Authentication
- Subject: NSURLDownload with Authentication
- From: Appa Rao Mulpuri <email@hidden>
- Date: Thu, 04 Sep 2014 12:44:15 +0000
- Thread-topic: NSURLDownload with Authentication
Hi,
I am trying to add the authentication logic for the existing code with the NSURLDownload, but download:canAuthenticateAgainstProtectionSpace and download:didReceiveAuthenticationChallenge: are not being called with the below sample code base. But Apple Documentation says:
* If the request is associated with an NSURLConnection or NSURLDownload object, that object’s delegate receives aconnection:canAuthenticateAgainstProtectionSpace:<https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSURLConnectionDelegate/connection:canAuthenticateAgainstProtectionSpace:> (or download:canAuthenticateAgainstProtectionSpace:) message. This allows the delegate to analyze properties of the server, including its protocol and authentication method, before attempting to authenticate against it. If your delegate is not prepared to authenticate against the server’s protection space, you can return NO, and the system attempts to authenticate with information from the user’s keychain.
I am not getting what I am doing wrong here trying on 10.9.4. Why delegates are not being called?
@interface PGAppDelegate : NSObject <NSApplicationDelegate>
{
NSURLDownload *mURLDownload;
}
@property (assign) IBOutlet NSWindow *window;
@end
@implementation PGAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@“Some URL with HTTPS – url with image will work"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:120];
mURLDownload = [[NSURLDownload alloc] initWithRequest:urlRequest delegate:self];
[mURLDownload setDestination:@"/Users/dev/Desktop/imageData" allowOverwrite:YES];
}
#pragma mark NSURLDownload delegate methods
- (void)downloadDidBegin:(NSURLDownload *)download
{
NSLog(@"%s", __FUNCTION__);
}
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
{
NSLog(@"Download failed! Error - %@ %@",
[error localizedDescription],
[error userInfo]);
}
- (void)download:(NSURLDownload *)download didReceiveDataOfLength:(NSUInteger)length
{
NSLog(@"%s length:%d", __FUNCTION__, length);
}
- (void)downloadDidFinish:(NSURLDownload *)download
{
NSLog(@"%s download: %@", __FUNCTION__, download);
}
- (void)download:(NSURLDownload *)download didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"%s response:%@", __FUNCTION__, response);
}
- (BOOL)download:(NSURLDownload *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
NSLog(@"%s protectionSpace:%@", __FUNCTION__, protectionSpace);
return YES;
}
- (void)download:(NSURLDownload *)download didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSLog(@"%s challenge:%@", __FUNCTION__, challenge);
}
@end
This email and any attachments are confidential, and may be legally privileged and protected by copyright. If you are not the intended recipient dissemination or copying of this email is prohibited. If you have received this in error, please notify the sender by replying by email and then delete the email completely from your system. Any views or opinions are solely those of the sender. This communication is not intended to form a binding contract unless expressly indicated to the contrary and properly authorised. Any actions taken on the basis of this email are at the recipient's own risk.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden